Member #151249

Member Since: September 15, 2010

Country: United States

  • Added a few lines to Casey’s excellent processing code to give multiline, 200ms tick marks, and screenshotting

    /******************************************************************************
    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
    
    Some mods by Humphrey Gardner  humphrey@hapitek.com
    8/6/2014
    Now five lines of EKG, tick marks every 200ms, click on frame to save to the executable's directory
    
    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.
    
    ******************************************************************************/
    
    
    import processing.serial.*;
    
    
    Serial myPort; // The serial port
    
    int xPos = 1; // horizontal position of the graph
    
    int tick=millis();
    
    float height_old = 0;
    
    float height_new = 0;
    
    float inByte = 0;
    
    int baseheight=100;
    
    
    
    void setup () {
    
      // set the window size:
      size(1600, 800);
    
    
      // List all the available serial ports
    
      println(Serial.list());
    
      // Open whatever port is the one you're using.
    
      myPort = new Serial(this, Serial.list()[1], 9600);
    
      // don't generate a serialEvent() unless you get a newline character:
    
      //myPort.bufferUntil('\n');
    
      // set inital background:
      background(0xff);
    }
    
    
    void draw () {
    
      // everything happens in the serialEvent()
    }
    
    
    void serialEvent (Serial myPort) {
    
      // get the ASCII string:
      String inString = myPort.readStringUntil('\n');
    
    
      if (inString != null) {
    
        // trim off any whitespace:
        inString = trim(inString);
    
    
        // If leads off detection is true notify with blue line
    
        if (inString.equals("!")) {
    
          stroke(0, 0, 0xff); //Set stroke to blue ( R, G, B)
    
          inByte = 512; // 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(inString);
    
         }
    
         //Map and draw the line for new data point
    
         inByte = map(inByte, 0, 512, 0, height/16);
    
         height_new = inByte;
    
         line(xPos - 1, baseheight-height_old , xPos, baseheight-height_new);
    
         height_old = height_new;
    
         //tickmark for 200 mseconds
         if (tick+200<=millis()){
           stroke(0, 0xff, 0); //Set stroke to green ( R, G, B)
           line(xPos, baseheight-20, xPos,baseheight+20);
           tick=millis();
         }
        //screen print if wished
    
        if(mousePressed) { 
           saveFrame(); 
        }
          // at the edge of the screen, go back to the beginning:
    
          if (xPos >= width) {
    
            xPos = 0;
            baseheight+=200;
          if (baseheight>height-100){
            xPos = 0;
            baseheight=100;
    
            background(0xff);}
    
          }
          else {
            // increment the horizontal position:
    
            xPos++;
          }
    
      }
    }
    
  • Aug 2013 - Quick build, beautifully compact, instructions are accurate. Running mine off a 9v battery with no problems.

No public wish lists :(