Gravity: MAX30102 Heart Rate and Oximeter Sensor Wiki - DFRobot

Introduction

DFRobot Gravity: MAX30102 heart rate and blood oxygen sensor module integrates the Maxim MAX30102 chip and an MCU heart rate and blood oxygen algorithm.
The MAX30102 uses PPG(PhotoPlethysmoGraphy) to measure data, which will be converted into heart rate and oximetry values when processed by the MCU, then output through I2C or UART, making the sensor easy to use and greatly reducing resource occupation of main controller. Meanwhile, the corresponding upper computer is provided to allow you to conveniently read data by a PC.

Note:

  1. The pressure may change when the finger is directly pressed down the sensor, which will affect the data output. So please try to fix the sensor on your finger.
  2. Wear the sensor on your finger and there is no difference in the direction of wearing.
  3. This product is not a professional medical instrument and should not be used as an auxiliary accessory in diagnosis and treatment.

Features

Applications

Specification

Dimension

Wear Instructions

Wear

Board Overview

Board Overview

Num Label Description
1 D/T I2C Data Line/TX
2 C/T I2C Clock Line/RX
3 GND Power -
4 VCC Power +

Tutorial

Requirements

Note: RTU library is the modbus library transplanted for Arduino based on Modbus RTU protocol. Install the RTU library before use.

Connection Diagram

Connection

Sample Code 1 - Get the Heart Rate and Blood Oxygen Data

Obtain the heart rate blood oxygen value, start measuring the heart rate when the sensor's red light is on, the heart rate data is updated every 4 seconds, the sensor data can still be obtained within 4 seconds, but the data obtained during the data update period does not change.
Please pay attention to the position of the communication switch.

/*!
  * @file  gainHeartbeatSPO2.ino
  * @n experiment phenomena: get the heart rate and blood oxygenation, during the update the data obtained does not change
  * @copyright   Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
  * @licence     The MIT License (MIT)
  * @author      PengKaixing(kaixing.peng@dfrobot.com)
  * @version     V1.0
  * @date        2021-06-21
  * @get         from https://www.dfrobot.com
  * @url         https://github.com/DFRobot/DFRobot_BloodOxygen_S
*/
#include "DFRobot_BloodOxygen_S.h"

#define I2C_COMMUNICATION  //use I2C for communication, but use the serial port for communication if the line of codes were masked

#ifdef  I2C_COMMUNICATION
#define I2C_ADDRESS    0x57
  DFRobot_BloodOxygen_S_I2C MAX30102(&Wire ,I2C_ADDRESS);
#else
/* ---------------------------------------------------------------------------------------------------------------
 *    board   |             MCU                | Leonardo/Mega2560/M0 |    UNO    | ESP8266 | ESP32 |  microbit  |
 *     VCC    |            3.3V/5V             |        VCC           |    VCC    |   VCC   |  VCC  |     X      |
 *     GND    |              GND               |        GND           |    GND    |   GND   |  GND  |     X      |
 *     RX     |              TX                |     Serial1 TX1      |     5     |   5/D6  |  D2   |     X      |
 *     TX     |              RX                |     Serial1 RX1      |     4     |   4/D7  |  D3   |     X      |
 * ---------------------------------------------------------------------------------------------------------------*/
#if defined(ARDUINO_AVR_UNO) || defined(ESP8266)
SoftwareSerial mySerial(4, 5);
DFRobot_BloodOxygen_S_SoftWareUart MAX30102(&mySerial, 9600);
#else
DFRobot_BloodOxygen_S_HardWareUart MAX30102(&Serial1, 9600); 
#endif
#endif

void setup()
{
  Serial.begin(115200);
  while (false == MAX30102.begin())
  {
    Serial.println("init fail!");
    delay(1000);
  }
  Serial.println("init success!");
  Serial.println("start measuring...");
  MAX30102.sensorStartCollect();
}

void loop()
{
  MAX30102.getHeartbeatSPO2();
  Serial.print("SPO2 is : ");
  Serial.print(MAX30102._sHeartbeatSPO2.SPO2);
  Serial.println("%");
  Serial.print("heart rate is : ");
  Serial.print(MAX30102._sHeartbeatSPO2.Heartbeat);
  Serial.println("Times/min");
  Serial.print("Temperature value of the board is : ");
  Serial.print(MAX30102.getTemperature_C());
  Serial.println(" ℃");
  //The sensor updates the data every 4 seconds
  delay(4000);
  //Serial.println("stop measuring...");
  //MAX30102.sensorEndCollect();
}

Expected Results

Result

API Function

/*!
 *  @brief Get heart rate and oxygen saturation and store them into the structure sHeartbeatSPO2
 *  @param NULL
 *  @return No value returned
 */
    void getHeartbeatSPO2();

/*!
 *  @brief Get the sensor board temp
 *  @param NULL
 *  @return Temp (unit: ℃)
 */
    float getTemperature_C();

/*!
 *  @brief Sensor starts to collect data
 *  @param NULL
 *  @return NULL
 */
    void sensorStartCollect();

/*!
 *  @brief Sensor stops collecting data
 *  @param NULL
 *  @return NULL
 */
    void sensorEndCollect();

Tutorial for Raspberry Pi

Requirements

Connection Diagram

Connection

Driver Installation

  1. Enable the I2C interface of Raspberry Pi, if enabled, skip this step. Open terminal, type the following command, and press Enter:

pi@raspberrypi:~ $ sudo raspi-config

Select "5 Interfacing Options" and press Enter. Select "P5 I2C" and press Enter to confirm "YES". Restart the Raspberry Pi master control.

  1. Install Python dependencies with git, and Raspberry Pi needs to be connected to the Internet. If done, skip this step. In the terminal, type the following commands and press Enter:

pi@raspberrypi:~ $ sudo apt-get update

pi@raspberrypi:~ $ sudo apt-get install build-essential python-dev python-smbus git

  1. Download the BloodOxygen driver libraries. In the terminal, type the following commands and press Enter:

pi@raspberrypi:~ $ cd Desktop/ pi@raspberrypi:~/Desktop $ git clonehttps://github.com/DFRobot/DFRobot_BloodOxygen_S

Sample Code 1 - Get the Heart Rate and Blood Oxygen Data (gain_heartbeat_SPO2.py)

pi@raspberrypi:~/Desktop $ cd DFRobot_BloodOxygen_S/python/raspberry/example/gain_heartbeat_SPO2/

pi@raspberrypi:~/Desktop/DFRobot_BloodOxygen_S/python/raspberry/example/gain_heartbeat_SPO2/ $ python gain_heartbeat_SPO2.py

Result

Use Guide for the Master Computer

Connect the sensor to the USB-to-serial port module.

Click to download the master computer of SEN0344 Heart Rate and Oximeter Sensor.

After decompressing, run SEN0344.exe, select the serial port and baud rate and click to start the measurement.

Modbus RTU Protocols

Note: The communication interface uses UART

Transmit From Adevice to Bdevice
Functions Bdevice Addess Function Code Register Address Register Number CRC Check
Get the Heart Rate and Blood Oxygen Data 0×20 0×03/Read 0×00 0×06 0×00 0×04 CRC_h CRC_l
Get the Temperature 0×20 0×03 0×00 0×0A 0×00 0×01 CRC_h CRC_l
Receive Response from Bdevice
Functions Bdevice Addess Function Code Valid Bytes Data CRC Check
Get the Heart Rate and Blood Oxygen Data 0×20 0×03 0×08 SPO2(1byte) xx(1byte reseved) Heartbeat(4byte) xx(2byte reserved) CRC_h CRC_l
Get the Temperature 0×20 0×03 0×02 Temp_h Temp_l CRC_h CRC_l
Set the Sensor Transmit From Adevice
Functions Bdevice Addess Function Code Register Address Register Number CRC Check
Start to Collet Data 0×20 0×06 0×00 0×10 0×00 0×01 CRC_h CRC_l
Stop Colleting Data 0×20 0×06 0×00 0×10 0×00 0×02 CRC_h CRC_l
Set the Sensor Response From Bdevice
Functions Bdevice Addess Function Code Valid Bytes Data CRC Check
Start to Collet Data 0×20 0×06 0×00 0×10 0×00 0×01 CRC_h CRC_l
Stop Colleting Data 0×20 0×06 0×00 0×10 0×00 0×02 CRC_h CRC_l

CRC check

static uint16_t calculate_CRC(uint8_t *data, uint8_t len)
{
  uint16_t crc = 0xFFFF;
  for( uint8_t pos = 0; pos < len; pos++)
  {
    crc ^= (uint16_t)data[ pos ];
    for(uint8_t i = 8; i != 0; i--)
    {
      if((crc & 0x0001) != 0){
        crc >>= 1;
        crc ^= 0xA001;
      }else{
        crc >>= 1;
      }
    }
  }
  crc = ((crc & 0x00FF) << 8) | ((crc & 0xFF00) >> 8);
  return crc;
}

FAQ

For any questions, advice or cool ideas to share, please visit the DFRobot Forum.

More Documents