Fermion: MAX30102 Heart Rate and Oximeter Sensor V2.0 Wiki - DFRobot

Introduction

The DFRobot heart rate and oximeter sensor integrates the Maxim MAX30102 chip and an MCU with heart rate and oximetry 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.

Update: The sensor V2.0 is equipped with a microprocessor that integrates heart rate and oximetry algorithm, which can directly output the relevant data. And it supports I2C/UART communication.

Features

Applications

Specification

Board Overview

Board Overview

Board Overview

NO. Silkscreen Description
1 3V3 +
2 GND -
3 SCL I2C Clock Line
4 SDA I2C Data Line
5 RST Reset Pin
6 NC Empty Pin
7 3V3 +
8 GND -
9 RX Serial Port Received Pin
10 TX Serial Port Transmitted Pin
11 INT Interrupt Pin
The pulse when heart rate and blood oxygen data is updated
12 NC Empty Pin

Tutorial

Requirements

Connection Diagram

Connection Diagram

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

In this sample, the heart rate and blood oxygen data is obtained through interrupts, and the heart rate is measured when the sensor's red light is on. If the interrupts is shielded, the data can still be obtained, but during the update the data obtained does not change. Note: This sample requires the use of interrupt pins. Change the INT_PIN pin in the codes according to the master.

/*!
  * @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();
}

Result 2

Stop the measurements after measuring the heart rate and blood oxygen content for 5 times.

Tutorial of Raspberry Pi

Requirements

Connection Diagram

Connection Diagram

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.

  2. 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

  3. 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)

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.

API Functions List

/*!
 *  @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();

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