Save data from AD8232 ECG

My AD8232 is working really well, connected to an Arduino Uno. Whether using the example code on the Sparkfun page or someone else’s code for using Processing to visualize the ECG, it works and looks great.

My problem is I can’t find a way to successfully save the data so my students and I can do statistical analyses on the ECG. I tried saving it as a table, but there’s something wrong with it, when these files are opened and the values are plotted, it doesn’t resemble the ECG at all.

Is it possible saving the data to a text file is too slow to keep up with (even though the display on screen is fine), or is it an issue with inconsistent timing between data points?

Would really appreciate any feedback/advice!

James

The data coming from the sketch is just Y axis data, you’re losing time on the X axis.

What you’re going to want to do is modify the sketch to add a timestamp along with the Y axis data, printing millis just before the analog read should allow you to graph the output.

Thanks! This seems to work, but I’m not sure if there isn’t a better way? I think typing in the “\n” might be causing some issues in the data stream I’m trying to save.

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.print(millis());
      Serial.print(",");
      Serial.print(analogRead(A0));
      Serial.print("\n");
  }
  //Wait for a bit to keep serial data from saturating
  delay(1);
}

Looks like you’re trying to print a new line with the “\n”.

Omit that line and change the line above it to:

Serial.println(analogRead(A0));

and I think you’ll have what you’re looking for. :slight_smile: