@HarryLee186 wrote:
Hi,
Not sure what I’m doing wrong but I’ve got the below code yet it just outputs “Heart Rate: 10” and outputs 10 in the console, too. I’m using a heart rate sensor from PulseSensor.com with my Arduino. When I open the Arduino monitor separately it’s outputting the correct BPM.
#include "ofApp.h" int byteData; //-------------------------------------------------------------- void ofApp::setup() { ofSetLogLevel(OF_LOG_VERBOSE); //General setup of look of window. ofBackground(255); verdana14.load("verdana.ttf", 14, true, true); ofSetColor(0); if (!serial.setup("COM3", 115200)) { ofLogError() << "could not open serial port - listing serial devices"; serial.listDevices(); } } //-------------------------------------------------------------- void ofApp::update() { if (serial.available() < 0) { msg = "Arduino Error"; } else { //While statement looping through serial messages when serial is being provided. while (serial.available() > 0) { //byte data is being writen into byteData as int. byteData = serial.readByte(); //byteData is converted into a string for drawing later. msg = "Heart Rate: " + ofToString(byteData); } } } //-------------------------------------------------------------- void ofApp::draw() { //drawing the string version pf byteData on oF window. verdana14.drawString(msg, 50, 100); //printing byteData into console. cout << byteData << endl; }
I have ‘BPM’ as a variable in my Arduino code, found below.
#include <PulseSensorPlayground.h>volatile int BPM; volatile boolean QS = false; volatile int IBI = 600; volatile int Signal; volatile boolean Pulse = false; int redPin = 13; int greenPin = 12; int pulsePin = 0; int blinkPin = 11; void setup() { Serial.begin(115200); interruptSetup(); pinMode(redPin, OUTPUT); pinMode(greenPin, OUTPUT); } void loop(){ if (QS == true) { healthCheck(); Serial.print("Your Current Heart Rate Is: "); Serial.println(BPM); Serial.write(BPM); QS = false; } delay(2500); }
Does anyone know why it would be outputting 10? I have a feeling it’s to do with the byteData but I’m not overly sure!
Posts: 1
Participants: 1