
Arduino Quick Start
Environment setup: Refer to the Arduino IDE Getting Started Guide to install the IDE, and install the appropriate board manager and required libraries for the target development board.
Required libraries:
Hardware used:

G9 (SCL) and G10 (SDA).#include "M5Unified.h"
#include "MAX30100.h"
#define SAMPLING_RATE MAX30100_SAMPRATE_100HZ
#define IR_LED_CURRENT MAX30100_LED_CURR_24MA
#define RED_LED_CURRENT MAX30100_LED_CURR_27_1MA
#define PULSE_WIDTH MAX30100_SPC_PW_1600US_16BITS
#define HIGHRES_MODE true
MAX30100 sensor; // Instantiate a MAX30100 sensor class
void setup()
{
M5.begin();
M5.Power.begin(); // Init power
Serial.print("Initializing MAX30100..");
while (!sensor.begin()) { // Initialize the sensor
M5.Lcd.setCursor(50, 100);
M5.Lcd.println("Sensor not found");
delay(1000);
}
M5.Lcd.setRotation(3);
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setFont(&fonts::FreeMonoBold12pt7b);
M5.Lcd.setTextSize(1.5);
// Set up the wanted parameters
sensor.setMode(MAX30100_MODE_SPO2_HR);
sensor.setLedsCurrent(IR_LED_CURRENT, RED_LED_CURRENT);
sensor.setLedsPulseWidth(PULSE_WIDTH);
sensor.setSamplingRate(SAMPLING_RATE);
sensor.setHighresModeEnabled(HIGHRES_MODE);
}
void loop()
{
uint16_t ir, red;
sensor.update(); // Update sensor data
if (sensor.getRawValues(&ir, &red)) { // if get data
M5.Lcd.setCursor(5, 20);
M5.Lcd.printf("IR: %d", ir);
M5.Lcd.setCursor(5, 70);
M5.Lcd.printf("RED: %d", red);
}
delay(100); // Appropriate delay
M5.Lcd.fillScreen(BLACK);
}
