Greetings, Been using the Arduino and Processing sketches that Casey provided on an UNO with a level converter and it worked “OK”. That is until upgrading to Processing 3.5.3… That broke it…
After educational guidance from the giant generous brains at Processing.org, I re-wrote the processing sketch. It works very well. I automated the serial port ID, put the code lines in the sections where they belong, increased the speed to 38400 bps and added one pixel to the Pos++ so it actually adds 2 pixels in the line draw. This smooths out the line. I’ve included the processing code below. Give it a whirl and if you like, replace the example code on Github. This is freeware. Kudos to Casey (even though he moved on) and the folks at Processing forum for pushing me to learn how this works and solving the problem. Note to makers expressing displeasure of high noise: Dno not let the electrode wires lay on your body. I also found that RFI from my Galaxy Note8 causes a squiggly line.
While this project begun as an educational project for me and the grandkids, it has morphed into a most useful device since I had a heart attack in February. I am most appreciative for the free software that has proved beneficial in daily monitoring of my health. NOTE: I fully understand this device and software is for educational purposes only, and are not intended for official medical use. But it is useful. Some info is better than none… When my chest was hurting I hooked myself up. When I saw the rhythm was so different than usual, I called 911. Thank GOD I did.
I’m working on an Android monitor for this via bluetooth or USB OTG.
Thank you!
John
p.s. Sorry for the long winded write-up
************* Arduino Sketch Below ********************
Edited by moderator to add code tags.
/******************************************************************************
Heart_Rate_Display.ino
Demo Program for AD8232 Heart Rate sensor.
Casey Kuhns @ SparkFun Electronics
6/27/2014
https://github.com/sparkfun/AD8232_Heart_Rate_Monitor
The AD8232 Heart Rate sensor is a low cost EKG/ECG sensor. This example shows
how to create an ECG with real time display. The display is using Processing.
This sketch is based heavily on the Graphing Tutorial provided in the Arduino
IDE. http://www.arduino.cc/en/Tutorial/Graph
Resources:
This program requires a Processing sketch to view the data in real time.
Development environment specifics:
IDE: Arduino 1.0.5
Hardware Platform: Arduino Pro 3.3V/8MHz
AD8232 Heart Monitor Version: 1.0
This code is beerware. If you see me (or any other SparkFun employee) at the
local pub, and you've found our code helpful, please buy us a round!
Distributed as-is; no warranty is given.
******************************************************************************/
void setup() {
// initialize the serial communication:
Serial.begin(9600);
pinMode(10, INPUT); // Setup for leads off detection LO +
pinMode(11, INPUT); // Setup for leads off detection LO -
}
void loop() {
if((digitalRead(10) == 1)||(digitalRead(11) == 1)){
Serial.println('!');
}
else{
// send the value of analog input 0:
Serial.println(analogRead(A0));
}
//Wait for a bit to keep serial data from saturating
delay(1);
}
********************* End Arduino Sketch *******************************
********************* Processing Sketch Below ***********************************
import processing.serial.*;
Serial s; // The serial port
int xPos = 1; // horizontal position of the graph
float height_old = 0;
float height_new = 0;
float inByte = 0;
static final int PORT_INDEX = 0, BAUDS = 38400;
String hrNumber = "";
void setup () {
noLoop();
final String[] ports = Serial.list();
printArray(ports);
new Serial(this, ports[PORT_INDEX], BAUDS).bufferUntil(ENTER);
size(1900, 400);
}
void serialEvent(final Serial s) {
hrNumber = s.readString().trim();
redraw = true;
println(hrNumber);
}
void draw ()
{
// background(0xff);
if (hrNumber.equals("!")) {
stroke(0, 0, 0xff); //Set stroke to blue ( R, G, B)
inByte = 200; // middle of the ADC range (Flat Line)
}
// If the data is good let it through
else {
stroke(0xff, 0, 0); //Set stroke to red ( R, G, B)
inByte = float(hrNumber);
}
//Map and draw the line for new data point
inByte = map(inByte, 0, 1023, 0, height);
height_new = height - inByte;
line(xPos - 1, height_old, xPos, height_new);
height_old = height_new;
// at the edge of the screen, go back to the beginning:
if (xPos >= width) {
xPos = 0;
background(0xdd);
} else {
// increment the horizontal position:
xPos = xPos += 2;
}
}
********************** END Processing Sketch ******************************