Initial report by Peter Darche?, 3, 4, 2012

Introduction

Electrical Activity in the Body

For our bodies to move, think, and regulate themselves, the cells, organs and systems that carry out these functions need some ability to receive and transmit appropriate control signals. The organ system responsible for transmitting these signals is the nervous system, and it sends them as electrochemical impulses propagated through networks of neurons. Neurons gain their electrical properties by creating voltage differences across their cell walls through the segregation of positively and negatively charged ions inside and outside the cell. Specialized proteins embedded in neuronal membranes works to pump out positive ions and keep in negative ones, so that in their resting state they have a net negative charge. When a neuron is sufficiently stimulated by an adjacent neuron, a threshold is met and these channels open, allowing the positive ions to rush in, causing a causing spike in voltage. This process, called depolarization, creates minute changes in voltage that are detectable on the skin.

ECG

Electrocardiography is a transthoracic (across the chest) interpretation of this electrical activity - specifically, the activity of the heart - over a period of time, using electrodes attached to the outer surface of the skin. An ECG device detects and amplifies the electrical changes that are caused when the motor neurons in the heart depolarize. When these cells are depolarized, additional neurotransmitters are released across the neuromuscular junction (the point connecting nerve cells to muscle cells) causing connecting muscle tissue to contract. During each heartbeat a healthy heart will have an orderly progression of a wave of depolarisation that is triggered by the cells in thesinoatrial node, spreads out through the atrium and then over the ventricles. This is detected as tiny rises and falls in the voltage between two electrodes placed either side of the heart which is displayed as a wavy line either on a screen or on paper. This display indicates the overall rhythm of the heart and weaknesses in different parts of the heart muscle.

The characteristic spike of the ECG is a set of waves, each representing a different stage in this cardiac cycle. The initial hump (prior to the spike), is called the P wave, and represents the electrical vector that beings in the sinoatrial node and moves to the atrioventricular node. Following the P wave comes the QRS complex, the set of waves which make up the spike we’re all used to. It is the result of the rapid depolarization of the right and left ventricles. These ventricles have significantly more mass than other areas of the heart and therefore have many more motor neurons. More neurons means more electrical activity, hence the large spike. The QRS complex is followed by the T wave, which represents the repolarization of the neurons in the heart.

Gif of the cardiac cycle

ECG measures the same underlying physical phenomena as electromyography and electroencephalography. (Electromyography gets its name from the myosin fibers that make up muscle tissue, and electroencephalography gets its name for an anachronistic name for the brain, the encephalon ). The difference between the two consists in the location of the electrodes, and therefore the dominant electrical signals detected.

Polar wearlink

The T31 Coded transmitter is a small, waterproof, wireless, band-mounted, ecg device produced by the Polar company and costing between 35 and 50 dollars (depending on vendor). Though it it uses the same mechanism to pick up voltage differences as an ECG, it exists simply to wirelessly transmit heart rate data, and therefore does not produce the graph or visual representation of the heart’s voltage changes. It does, however, make it very easy access heart rate data.

Sparkfun Heart Rate Monitor Interface

The Heart Rate Monitor Interface (HRMI) is an intelligent peripheral device that converts the ECG signal from Wearlink transmitters into easy-to-use heart rate data. It implements a “sophisticated” algorithm for computing an average heart rate even with noisy or intermittent data from the transmitter. The HRMI also provides analog inputs and a digital input/output utility port to ease integration into custom applications.

Sources

The Wearklink is available from a number of vendors, and ranges in price from about 50 to 70 dollars. They are available from a number of vendors, but I found that Amazon consistently had the lowest prices and most convenient ordering. This isn’t to say that they must be purchased online. Because they are targeted primarily at training athletes, they are available at athletics stores across the city and country. REI, for example, on Houston and Lafayette has them for about 65 dollars.

The HRMI, on the otherhand, is produced exclusively by Sparkfun and Dan Julio Designs, and is therefore only available on Sparkfun. It costs 60 dollars and is generally in stock.

As you might expect, ordering both from Amazon and Sparkfun was easy and I received the devices, without issue, in about a week.

Applications

The Polar monitor and HRMI board are designed to work together to make it easy to get heart rate information and are therefore best suited to projects that need........... heart rate information! Because it does that, and only that, well, it’s naturally suited to any application in which heart rate information and ease of use are necessary. This could include:

  • Custom exercise equipment
add heart rate data to your home stationary bike!
get heart rate data while riding your non-stationary bike!
  • Portable heart rate monitoring devices
connect the board to a datalogger and track your heart rate throughout the day!
measure your heart rate while you do things like play ultimate frisbee!
  • Bio-feedback devices
make a stress ball that helps you see how you’re calming down as you use it
use it to practice calming down while doing things that stress you out, like public speaking.
  • Heartbeat aware body-worn electronics
make an awesome t-shirt or hat, or cape, the uses EL wire to show your heart rate.
  • Physical or digital art pieces which include heartbeat
make a sculpture that shows your heart beating when you walk up to it!

Electrical Characteristics

Manual, Datasheet, Polar RMCM-01 chip datasheet

Unfortunately, Polar does not seem to expect or want individuals to mess with the Wearlink sensor itself, as no datasheets or other information about its electrical characteristics seem to be available. However, the HRMI is well-documented and the characteristics are below.

HRMI characteristics

parametermintypicalmaxUnitConditions
external voltage supply3.6 5.5Vwhen powered from external voltage supply
USB Voltage Supply4.555.5VWhen Powered from USB
External Current3045mANo connection to any Analog or Utility port signal
Reception Range8092100cmTypical using a T31 transmitter
Analog Voltage Range 5.5 kHz
Utility Port Input Low LevelVSS/VSS0.15*VCC/0.8 V/V3.3V <= VCC <= 4.5/ 4.5V <= VCC <= 5.5
Utility Port Input High Level0.25* VCC + 0.8/ 2VCCV4.5V <= VCC <= 5.5V
Utility Port Output Low Level 0.6VLol = 8.5 mA, VCC = 4.5V
Utility Port Output High LevelVCC 0.7 VLoh = -3.0mA, VCC = 4.5V
Maximum Analog Port Source Impedance  10KOhm Note 2
Maximum output current sunk by any Utility Port Signal   25mANote 3
Maximum output current sourced by any Utility Port signal  25mANote 3
Capacitive Loading Analog and Utility Ports   55 pF
Configuration EEPROM write cycles100K1M Write CyclesTa <=85 degrees C
Configuration EEPROM characteristic retention40  YearProvided no other specifications are violated
Operating Temperature Range0 2060degrees C
Storage Temperature Range-302070degrees C

Notes

  1. VSS is on-board ground, VCC is on-board voltage supply
  2. The maximum Analog Port Source impedance is required in order for the AD sampling time to be met.
  3. Total current sourced or sunk by all Utility Port signals must be less than 80 mA

Pin Descriptions

There are two sets of pins users will be most interested in: I/O pins, and the communication pins. Depending on what mode of communication the user selects, the latter set of pins will be the first a new uses needs to deal with. If he or she decides to use I2C, he or she will need to utilize the power, ground and Rx/Tx pins situated between the Mini-USB connection and the RMCM chip. Once a communication type has been selected, the user can then use the analog and digital I/O pins situated next to the PIC chip.

HRMI

The HRMI is a slave device. It responds to commands issued to it from a host controller. It interprets commands from either a serial or I2C interface. Both interfaces use the same physical I/O ports on the HRMI micro-controller. The interface type is selected by sampling jumper OP0 at power-on and persists until the next power-on reset. The HRMI is capable of receiving commands 250 mSec after being powered up. Unknown or illegal commands are ignored. Some commands cause the HRMI to generate a response which it transmits back to the host controller after processing the command. Commands are 1-byte (8-bits in length). They have ASCII representations that are an abbreviation of their function. Some commands are followed by an argument representing a single 8-bit numeric quantity. Responses consist of one or more numeric values. Commands and responses are encoded slightly differently for serial and I2C communication.

Commands and arguments sent through the serial interface are encoded as ASCII values. Commands are a single ASCII character with values between ‘A’ and ‘Z’. Arguments are one to three ASCII numbers “0” through “255” representing an 8-bit value. Commands are issued in Command Sequences. A Command Sequence consists of the command value followed by any required argument terminated with the Carriage Return character (0x0D). Space characters may be included between the command and argument or between the argument and the Carriage Return (<CR>). Any other characters or additional arguments cause the HRMI to ignore the Command Sequence up to the next Carriage Return. Responses consist of ASCII numbers (“0” through “255”) separated by spaces terminated with the Carriage Return character.

For example the ASCII character ‘G’ is used for the Get Heart Rate command. It is always followed by an argument with a value of 0 - 32 commanding the HRMI to return 0 - 32 heart rate values from its heart rate history buffer. The HRMI also includes two status bytes prior to the requested heart rate data. Sending the command G3<CR> or G 3 <CR> generates a response with the form 1 25 63 64 67 <CR> where the values “1” and “25” are the status bytes and the values “63”, “64” and “67” are the requested heart rate values (in beats-per-minute) from the heart rate history buffer.

I2C

The HRMI implements a simple 7-bit slave I2C device. It is configured with any 7-bit I2C address on the OP1-7 configuration jumpers at power-on. The HRMI implements only the mandatory I2C slave functionality described in the NXP Semiconductor document “UM10204 I2C-bus specification and user manual”. These functions include START condition, STOP condition, Acknowledge and 7-bit slave address. It does not support General Call address, 10-bit slave address, Software reset or Device ID. The maximum bit rate is 100 kHz. Commands and arguments are encoded as 8-bit binary values. Command Sequences consist of 1- or 2-byte I2C write sequences (the command byte followed by any required argument byte) followed by the STOP condition. The host controller must issue a read of the expected number of data bytes for commands that generate a response. The read should be issued following the write and before subsequent commands. The HRMI stretches the clock on the SCL line during the read while it fetches data bytes internally to satisfy the read. The HRMI will return the value 0x00 for host controller I2C reads that request more data than the is contained in the response or for reads without a prior command. The example shown in the Serial Interface section above would consist of the following bytes transmitted on the I2C interface for the command. <0x47><0x03> The following response data would be read (the host controller must read 5 bytes for this example). <0x01><0x19><0x3F><0x40><0x43> The HRMI can buffer multiple I2C commands and arguments in an internal 16-byte FIFO. However it can only process one command at a time that requires a response. This is because it resets the internal buffer it uses to hold responses each time a command is received from the I2C interface. The host controller must execute a read and obtain the response data for any command that generates a response before issuing another command.

Additional Parts

  • Mini-USB for serial connection
  • header-pins for I2C connection
  • Master device for providing commands

Code Samples

Simple Arduino Example from Bildr

//Arduino 1.0+ Compatible only

// Code to retrieve heartrate information from the Polar Heart Rate Monitor Interface via I2C
// Part: http://www.sparkfun.com/products/8661
// Article:  http://bildr.org/2011/08/heartrate-arduino/

#include "Wire.h"

#define HRMI_I2C_ADDR      127
#define HRMI_HR_ALG        1   // 1= average sample, 0 = raw sample

void setup(){
  setupHeartMonitor(HRMI_HR_ALG);
  Serial.begin(9600);
}

void loop(){

  char heartRate = getHeartRate();
  Serial.println("heart rate");
  Serial.println(heartRate);

  delay(200); //just here to slow down the checking to once a second
}

void setupHeartMonitor(int type){
  //setup the heartrate monitor
  Wire.begin();
  writeRegister(HRMI_I2C_ADDR, 0x53, type); // Configure the HRMI with the requested algorithm mode
}

char getHeartRate(){
  //get and return heart rate
  //returns 0 if we couldnt get the heart rate
  byte i2cRspArray[3]; // I2C response array
  i2cRspArray[2] = 0;

  writeRegister(HRMI_I2C_ADDR,  0x47, 0x1); // Request a set of heart rate values

  if (hrmiGetData(127, 3, i2cRspArray)) {
    return i2cRspArray[2];
  }
  else{
    return 0;
  }
}

void writeRegister(int deviceAddress, byte address, byte val) {
  //I2C command to send data to a specific address on the device
  Wire.beginTransmission(deviceAddress); // start transmission to device
  Wire.write(address);       // send register address
  Wire.write(val);         // send value to write
  Wire.endTransmission();     // end transmission
}

boolean hrmiGetData(byte addr, byte numBytes, byte* dataArray){
  //Get data from heart rate monitor and fill dataArray byte with responce
  //Returns true if it was able to get it, false if not
  Wire.requestFrom(addr, numBytes);
  if (Wire.available()) {

    for (int i=0; i<numBytes; i++){
      dataArray[i] = Wire.read();
    }

    return true;
  }
  else{
    return false;
  }
}
 

Simple Processing Example using Serial

// Demonstration program for communicating with the HRMI over a serial interface
//
// Include the serial library
import processing.serial.*;
// Variable declaration
Serial port;                                     // The serial port
byte[] rspCharArray = new byte[32];    // Where we'll put the raw data read from the HRMI
int[] rspArgArray = new int[3];            // Where we'll put the converted response values
int validData = 0;
int CR = 13;                           // <CR> constant
void setup() {
  // Open a specific serial device (this will change for each HRMI device)
  port = new Serial(this, "/dev/tty.usbserial-A9003PDh", 9600);

  // Setup the serialEvent to be called when we receive complete response
  // packets from the HRMI device
  port.bufferUntil(CR);
}
void draw() {
  // Send a command to get a single heart rate value
  validData = 0;
  port.write('G');
  port.write('1');
  port.write(CR);

  // Wait for a response from the HRMI device
  while (validData == 0) {
      delay(1000);                    // Delay 1 second between checks
  }

  // Display mode, count and heartrate
  if ((rspArgArray[0] & 0x01) == 0x01)
    print("Averaged mode ");
  else
    print("Raw mode ");    
  print(rspArgArray[1]); print(" "); // Count
  println(rspArgArray[2]);           // Heart rate
}
// Catch the event from the serial interface.  Make sure there is
// actually data to read before attempting to do any processing.
void serialEvent(Serial port) {
      if (port.readBytesUntil(CR, rspCharArray) != 0) {
        // Read bytes until we get to the end of the packet converting
        // each ASCII digit into a number.  We make use of the space
        // character between sets of digits to delimit numbers.
        //    Argument 0: Status Flags
      //    Argument 1: Second Count
        //    Argument 2: Heartrate
        //
        int ArgIndex = 0;
        int CharIndex = 0;
        for (int i=0; i<3; i++) rspArgArray[i] = 0;
        while (rspCharArray[CharIndex] != CR) {
          if (rspCharArray[CharIndex] != ((byte) ' ')) {
            rspArgArray[ArgIndex] = (rspArgArray[ArgIndex]*10) + (rspCharArray[CharIndex] -
((byte) '0'));
          } else {
            ArgIndex++;
          }
          CharIndex++;
        }
        validData = 1;
      }
}

Typical Behavior

The HRMI provides consistent, accurate raw and average heart beat measurements, making it an ideal for any project looking to incorporate such data. A few things to note, though. First, the board is initially configured for USB communication. This means that the SJ1 solder jumper is connected and the OP0 jumper is not. If you are planning to create a project using I2C communication, you’ll need to remove the solder from SJ1 and connect the pads on OP0. Also, if you’ve done that and notice that the status light is still no blinking (meaning heart rate data is being transmitted), you have to either adjust the sensor so it is more directly over the heart, or your skin may be simply too dry. If you’ve readjusted and it still isn’t picking up data, try licking your thumbs and pushing them down on the on the electrodes on the strap.

Application Notes

The Wearlink + HRMI have a number of pros and cons. Together, the two are very easy to setup and use, provide a reliable signal, and are definitely designed to make it easy to incorpate HR data into new projects. Unfortunately, this ease of use comes at cost in terms, both monetary and in terms of data. Together, the two will cost you about $100 to buy and you’re only given a limited range of data. Also, given that you’ll need a master device, the HRMI board, and the strap, you may find that the hardware is too large for some applications.

pros

  • very easy to set up
  • reliable signal
  • relatively easy to change users/put on the device
  • well documented

cons

  • not particularly cheap
  • potentially large (depending on application)
  • provides limited range of data

References and Bibliography

wikipedia sources re: ecg, cardiac cycle:
http://en.wikipedia.org/wiki/Nervous_system
http://en.wikipedia.org/wiki/Action_potential
http://en.wikipedia.org/wiki/Cardiac_cycle
http://en.wikipedia.org/wiki/Electrocardiography
http://en.wikipedia.org/wiki/Depolarization
http://en.wikipedia.org/wiki/Polarization_
sparkfun product site
http://www.sparkfun.com/products/8661

polar product site
http://www.polar.fi/en/products/accessories/T31_coded_transmitter

polar RMCM heart rate receiver chip data sheet
[[http://www.sparkfun.com/datasheets/Wireless/General/RMCM01.pdf

HRMI manual
[[http://danjuliodesigns.com/sparkfun/hrmi_assets/hrmi.pdf

Bildr quickstart project site [[http://bildr.org/2011/08/heartrate-arduino/