Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not displaying BPM and IBI #27

Open
VeiTheOne opened this issue Mar 24, 2023 · 9 comments
Open

Not displaying BPM and IBI #27

VeiTheOne opened this issue Mar 24, 2023 · 9 comments

Comments

@VeiTheOne
Copy link

It says in the code that it's TODO for next project. Has anyone done this second project?

Plus, how can I have it show the BPM and IBI? I am using the Phidget VINT hub if that's a factor.

@biomurph
Copy link
Contributor

@VeiTheOne
Please provide more information to help troubleshoot your question.
What exactly in the code is not functioning as expected?
What other code are you using with the code in this repo?
What hardware board are you using?
Etc.?

@VeiTheOne
Copy link
Author

I am using Phidget's VINT Hub as the board. The Graph visualizer works fine, and I have been trying to get it to display the BPM. The code works, there's just nothing to get the BPM. And I'm using the code listed here.

Here's my current code, which is unchanged.

import com.phidget22.*;


VoltageRatioInput heartSensor;
Scrollbar scaleBar;

PFont font;
PFont portsFont;

//Holds heartbeat data
float [] pulses;      
float [] scaledPulses;   

float zoom;
color eggshell = color(255, 253, 248);

//Sizing of windows
int PulseWindowWidth = 490;
int PulseWindowHeight = 512;
int BPMWindowWidth = 180;
int BPMWindowHeight = 340;

void setup() {
  size(700, 600);
  frameRate(100);
  font = loadFont("Arial-BoldMT-24.vlw");
  textFont(font);
  textAlign(CENTER);
  rectMode(CENTER);
  ellipseMode(CENTER);

  //Create scroll bar for zooming
  scaleBar = new Scrollbar (400, 575, 180, 12, 0.0, 1.0);
  
  pulses = new float[PulseWindowWidth];
  scaledPulses = new float[PulseWindowWidth];
  
  //Default zoom
  zoom = 0.75;                               

  //Drawing
  resetDataTraces();
  background(0);
  drawDataWindows();
  drawHeart();
  fill(eggshell);

  //Phidgets initialize 
  try {
    //Create
    heartSensor = new VoltageRatioInput();
    //Address
    heartSensor.setHubPort(0);
    heartSensor.setIsHubPortDevice(true);
    //Open
    heartSensor.open(1000);
    //Set data interval to minimum | This will increase the data rate from the sensor, and make your graph more responsive
    heartSensor.setDataInterval(heartSensor.getMinDataInterval());
  }
  catch(Exception e) {
    e.printStackTrace();
  }
}

void drawDataWindows() {
  noStroke();
  fill(eggshell);
  rect(255, height/2, PulseWindowWidth, PulseWindowHeight);
  rect(600, 385, BPMWindowWidth, BPMWindowHeight);  
}

void drawHeart() {
  fill(250, 0, 0);
  stroke(250, 0, 0);
  smooth();
  bezier(width-100, 50, width-20, -20, width, 140, width-100, 150);
  bezier(width-100, 50, width-190, -20, width-200, 140, width-100, 150);
  strokeWeight(1);
}

void drawPulseWaveform() {
  float pulseVal = 0;
  try {
    pulseVal = (float)heartSensor.getVoltageRatio();
  }
  catch(Exception e) {
    e.printStackTrace();
  }
  
  pulses[pulses.length-1] = ((pulseVal - 0.5)* 512);   //pulseVal is between 0 and 1. Center and scale up to fit window.
  zoom = scaleBar.getPos();  
  for (int i = 0; i < pulses.length-1; i++) {
      pulses[i] = pulses[i+1];                         // shifting all raw datapoints one pixel left
      scaledPulses[i] = pulses[i] * -zoom + height/2;  // adjust the raw data to the selected scale
  }
  stroke(250, 0, 0);                               
  noFill();
  beginShape();                                  
  for (int x = 1; x < scaledPulses.length-1; x++) {
    vertex(x+10, scaledPulses[x]);                    //draw a line connecting the data points
  }
  endShape();
}

void draw() {
  background(0);
  noStroke();
  drawDataWindows();
  drawPulseWaveform();
  drawHeart();
  
  fill(eggshell);
  text("Pulse Sensor Amped Visualizer - Phidgets", 245, 30);
  text("IBI",600,585); // TODO for next project
  text("BPM",600,200); // TODO for next project
  text("Pulse Window Scale " + nf(zoom, 1, 2), 150, 585);

  //Manage scroll bar
  scaleBar.update (mouseX, mouseY);
  scaleBar.display();
}

void resetDataTraces() {
  for (int i=0; i<pulses.length; i++) {
    pulses[i] = height/2;
  }
}

@biomurph
Copy link
Contributor

@VeiTheOne
That is not the code that is in this repo.
I don't have experience with Phidget.

You may need to ask the source of that code about your problems.

@VeiTheOne
Copy link
Author

VeiTheOne commented Mar 25, 2023 via email

@VeiTheOne
Copy link
Author

Ok, Email looks like shit.

Well, I’m just trying to get a bpm calculation working for an upcoming competition. Thanks tho.

@VeiTheOne
Copy link
Author

You may need to ask the source of that code about your problems.

And they don't have an issues page.

@biomurph
Copy link
Contributor

You may need to ask the source of that code about your problems.

And they don't have an issues page.

Dang. Is there any community around it? A forum or anything?

Our PulseSensor Arduino library does all the work to find the heartbeat in the signal and derive BPM and IBI.
What are you using for heartbeat detection? What hardware?
Or are you simulating?

@VeiTheOne
Copy link
Author

VeiTheOne commented Mar 25, 2023

We got 3 pulse sensors from Phidgets. And I can't seem to find it. We were able to display the raw voltage, but none of us have yet to figure out how to get it to display the BPM. What's worse is that they said on the Phidgets page says "Stay tuned for part two." of the project. There has never been updates since, and that's where I'm stuck at, sadly.

I'm using a VINT HUB0001_0 from Phidgets as the "board".

@biomurph
Copy link
Contributor

Interesting. Looks like a lot of engineering for some simple interfacing.

It would take some ramping up for us to make PulseSensor compatible with Phidgets.
Give me a bit of time to investigate how their tech works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants