Highlights

Posted by : Noctis King Saturday, May 3, 2014

The program of collection and graphing data

    This program ran on the Arduino and used to collect and graphing the heart rate data and calculated the BPM (heart rate/minute).
    There were three parts of this program: the collecting part, graphing part and calculating part. The collecting part was the most important part in these parts, because the data which collected from this part was necessary from next two part.
    The program would use the ECG which connected on the Arduino to detect the heart beat from the user. The user can set the different port if they wanted to change the port of ECG;
    After the program got the real-time data, it would start the graphing and calculating.
    In the graphing part, the program would group the heart beat on a new window.
    In the calculating part, the program would find out the data of changing and judging them weather a heart beat and counted the number of heart beat to calculated the BPM.

import processing.serial.*;

Serial myPort; 
int val, screen_increment, old_x=0, old_y=0;  
String inString;  
int lf = 10; 
double bpm,t,lbpm;
int lval=510;
void setup() 
{

  size(displayWidth-100, 1000);  //set the size of window
  
  String portName = Serial.list()[0]; //the port of input
  println(Serial.list());
  
  myPort = new Serial(this, portName, 115200);
  myPort.bufferUntil(lf);
  background(0,0,0);//the color of background of window
}

void draw()
{

}

void serialEvent(Serial myPort) { 

  inString = myPort.readString();
  inString = trim(inString);
  val = int(inString);//get the value of rate
  strokeWeight(5);
  stroke(255, 255, 255);
  println(val);
  
  line(old_x, old_y, screen_increment, 1000-val); //graph the hate rate
  
  old_x = screen_increment;
  old_y = 1000-val;
  
  screen_increment=screen_increment+2;
  if(screen_increment>(displayWidth-100))
  {
    background(0,0,0); 
    screen_increment=-50; 
  old_x = -50;
  old_y = 0;
  }
  if(val-lval>7) //calculate the BPM
  {
    t=t+1;
    lval=val;
  }
  if(val<lval)
  {
    lval=val;
    t=t+1;
  }
  if(val-lval>5)
  {
    bpm=60/(0.015*t);
    t=0;
  }
  
  if (bpm<130 && lbpm-bpm<40)
  {
  text(bpm+ "                                      BPM",600,200);
  //println(bpm);
  lbpm=bpm;
  }
}



Leave a Reply

Subscribe to Posts | Subscribe to Comments

- Copyright © 2013 Group 106-11 - Date A Live - Powered by Blogger - Designed by Johanes Djogan -