Cannot get variable to pass to Processing

Hello.

I cannot figure out how to get this MBP variable to display on a graph in Processing. I feel like there might be something wrong with the loop or how it’s reaching the graph on Processing, but I’m not too sure what exactly. Below I have the code pertaining to this variable.

void loop() {
delay(20);
pulseSensor.outputSample();
for (int i = 0; i < PULSE_SENSOR_COUNT; ++i) {
if (pulseSensor.sawStartOfBeat(i)) {
pulseSensor.outputBeat(i);

lastBeatSampleNumber = pulseSensor.getLastBeatTime(i);

  • if(i == 1){*
  • PTT = lastBeatSampleNumber[1] - lastBeatSampleNumber[0];*
    _ MBP = 67.5185 * log(15147.5828/pow(PTT, 2));_
  • pulseSensor.outputToSerial(’|’, PTT);*
  • pulseSensor.outputToSerial(’|’, MBP);*
  • }*
  • }*
  • }*
    }

Please use code tags. (Read the how-to-use-this-forum sticky post.)

Show all the code. We need to see where pulseSensor is defined. Is that from a library? Where did the library come from?

I am experimenting with the Pulse Sensor Playground Library. I am just modifying it so it can serve a different purpose. Here is my code:

#define USE_ARDUINO_INTERRUPTS true
#include <PulseSensorPlayground.h>

const int OUTPUT_TYPE = PROCESSING_VISUALIZER;

const int PULSE_SENSOR_COUNT = 2;

const int PULSE_INPUT0 = A0;
const int PULSE_BLINK0 = 13;
const int PULSE_FADE0 = 5;

const int PULSE_INPUT1 = A1;
const int PULSE_BLINK1 = 12;
const int PULSE_FADE1 = 11;

const int THRESHOLD = 550;

PulseSensorPlayground pulseSensor(PULSE_SENSOR_COUNT);

unsigned long lastBeatSampleNumber[PULSE_SENSOR_COUNT];
int PTT;
int MBP;
void setup() {

  Serial.begin(250000);

  pulseSensor.analogInput(PULSE_INPUT0, 0);
  pulseSensor.blinkOnPulse(PULSE_BLINK0, 0);
  pulseSensor.fadeOnPulse(PULSE_FADE0, 0);

  pulseSensor.analogInput(PULSE_INPUT1, 1);
  pulseSensor.blinkOnPulse(PULSE_BLINK1, 1);
  pulseSensor.fadeOnPulse(PULSE_FADE1, 1);

  pulseSensor.setSerial(Serial);
  pulseSensor.setOutputType(OUTPUT_TYPE);
  pulseSensor.setThreshold(THRESHOLD);

  if (!pulseSensor.begin()) {

    for (;;) {
      digitalWrite(PULSE_BLINK0, LOW);
      delay(50);
      digitalWrite(PULSE_BLINK0, HIGH);
      delay(50);
    }
  }
}

void loop() {
  delay(20);
  pulseSensor.outputSample();
  for (int i = 0; i < PULSE_SENSOR_COUNT; ++i) {
    if (pulseSensor.sawStartOfBeat(i)) {
      pulseSensor.outputBeat(i);

      lastBeatSampleNumber[i] = pulseSensor.getLastBeatTime(i);
      if(i == 1){
        PTT = lastBeatSampleNumber[1] - lastBeatSampleNumber[0];
        MBP = 67.5185 * log(15147.5828/pow(PTT, 2));
        pulseSensor.outputToSerial('|', PTT);
        pulseSensor.outputToSerial('|', MBP);
      }
    }
  }

}

You mean this one? GitHub - WorldFamousElectronics/PulseSensorPlayground: A PulseSensor library (for Arduino) that collects o

Looks like a commercial company. What does their customer-support say?

What do you see when you open the Serial Monitor instead of Processing? Does it look like what the Processing program is expecting?

I don’t even know if they have a customer support service or not.

Serial Monitor shows the data directly from the PPG device (which is using this code), but not exactly the variables I am hoping for.

If you need to see the Processing code or anything else in general, let me know.

Just for clarity: I have gotten the PTT variable to work. The only variable that I cannot get to work is the MBP one, which I created myself.

What values are you expecting to get for MBP? You declared it as int so if it's supposed to be a number like 0.123 then that will just come out as zero.

Instead of using Processing, try just opening Tools > Serial Monitor in the Arduino IDE to see what the raw data looks like. Make sure to set the baud rate menu at the bottom right corner of Serial Monitor to 250000.

MorganS, that was the problem; I didn't realize I set the variable as an integer rather than a float. My bad. Thank you all for your help.