MAX30102 Heart rate monitor

[MAX30102.js] is a module to handle the MAX30102 pulse oximetry and heart-rate monitor biosensor.

This module returns the raw IR and red light values as an array, but it's then up to you to analyse the data to get a heart rate or oxygen value.

Wiring

The MAX30102 is a 1.8v device so requires its own voltage regulator (unless you have a breakout board that contains one). However the I2C lines are still capable of 3.3v.

Software

var i2c = new I2C();
i2c.setup({scl: ..., sda: ...});
var hrm = require("MAX30102").connect(i2c);

function getHRM() {
  print("Starting HRM...");
  hrm.init();
  var cnt = 200;
  var rawdata = new Uint8Array(cnt*6);
  var dcnt = 0;
  // we wait for the HRM readings to settle down to sensible values
  print("Waiting for HRM... wait 5 seconds");
  var i = setInterval(function() {
    hrm.readFIFORaw();
  });
  setTimeout(function() {    
    print("Reading HRM... wait 10 seconds");
    clearInterval(i);
    hrm.readFIFORaw(); // throw away the first set of readings...

    var i = setInterval(function() {
      // Save the raw data into an array
      d = hrm.readFIFORaw();
      rawdata.set(d, dcnt*6);
      dcnt += d.length/6;
      // when full, stop the HRM and then decode the data
      if (dcnt>=cnt) {
        hrm.kill();
        clearInterval(i);
        drawHRM(rawdata);
      }
    }, 200);
  }, 5000);
}

function drawHRM(rawdata) {
  var cnt = rawdata.length/6;
  var dred = new Uint32Array(cnt);
  var dir = new Uint32Array(cnt);
  hrm.decodeRawData(rawdata, dred, dir);
  var g = Graphics.createArrayBuffer(cnt,60,1);
  var red = E.sum(dred)/cnt;
  var ir = E.sum(dir)/cnt;
  g.clear();
  g.drawString("Red",2,2);
  g.moveTo(-100,0);
  for (var i=0;i<cnt;i++)
    g.lineTo(i,30+(dred[i]-red)/20);
  g.dump();
  g.clear();
  g.drawString("IR",2,2);
  g.moveTo(-100,0);
  for (var i=0;i<cnt;i++)
    g.lineTo(i,30+(dir[i]-ir)/40);
  g.dump();
}

getHRM();

Reference

// Start the heart rate monitor
MAX30102.prototype.init = function () { ... }

// Stop the heart rate monitor
MAX30102.prototype.kill = function () { ... }

// read one set of FIFO data, return {red,ir}
MAX30102.prototype.readFIFO = function () { ... }

// Read all the currently available FIFO data and return it raw
MAX30102.prototype.readFIFORaw = function () { ... }

// Decode an array of raw FIFO data into red&ir arrays (Uint32Array is preferable)
MAX30102.prototype.decodeRawData = function (d, red, ir) { ... }

exports.connect = function (i2c, options) { ... }

Using

(No tutorials are available yet)

Buying

This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.