/*!
* @file SPO2.ino
* @brief Display heart-rate and SPO2 on serial in real-time, normal SPO2 is within 95~100
* @n Try to fix the sensor on your finger in using to avoid the effect of pressure change on data output.
* @n This library supports mainboards: ESP8266, FireBeetle-M0, UNO, ESP32, Leonardo, Mega2560
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @licence The MIT License (MIT)
* @author [YeHangYu](hangyu.ye@dfrobot.com)
* @version V0.1
* @date 2020-05-29
* @url https://github.com/DFRobot/DFRobot_MAX30102
*/
#include <DFRobot_MAX30102.h>
DFRobot_MAX30102 particleSensor;
/*
Macro definition options in sensor configuration
sampleAverage: SAMPLEAVG_1 SAMPLEAVG_2 SAMPLEAVG_4
SAMPLEAVG_8 SAMPLEAVG_16 SAMPLEAVG_32
ledMode: MODE_REDONLY MODE_RED_IR MODE_MULTILED
sampleRate: PULSEWIDTH_69 PULSEWIDTH_118 PULSEWIDTH_215 PULSEWIDTH_411
pulseWidth: SAMPLERATE_50 SAMPLERATE_100 SAMPLERATE_200 SAMPLERATE_400
SAMPLERATE_800 SAMPLERATE_1000 SAMPLERATE_1600 SAMPLERATE_3200
adcRange: ADCRANGE_2048 ADCRANGE_4096 ADCRANGE_8192 ADCRANGE_16384
*/
#include <Wire.h>
#include <LCD_I2C.h>
LCD_I2C lcd(0x27); // Default address of most PCF8574 modules, change according
void setup()
{
lcd.begin(); // If you are using more I2C devices using the Wire library use lcd.begin(false)
// this stop the library(LCD_I2C) from calling Wire.begin()
lcd.backlight();
lcd.home();
lcd.clear();
Serial.begin(9600);
/*!
*@brief Init sensor
*@param pWire IIC bus pointer object and construction device, can both pass or not pass parameters (Wire in default)
*@param i2cAddr Chip IIC address (0x57 in default)
*@return true or false
*/
while (!particleSensor.begin()) {
//lcd.println("MAX30102 was not found");
delay(1000);
}
/*!
*@brief Use macro definition to configure sensor
*@param ledBrightness LED brightness, default value: 0x1F(6.4mA), Range: 0~255(0=Off, 255=50mA)
*@param sampleAverage Average multiple samples then draw once, reduce data throughput, default 4 samples average
*@param ledMode LED mode, default to use red light and IR at the same time
*@param sampleRate Sampling rate, default 400 samples every second
*@param pulseWidth Pulse width: the longer the pulse width, the wider the detection range. Default to be Max range
*@param adcRange ADC Measurement Range, default 4096 (nA), 15.63(pA) per LSB
*/
particleSensor.sensorConfiguration(/*ledBrightness=*/50, /*sampleAverage=*/SAMPLEAVG_4, \
/*ledMode=*/MODE_MULTILED, /*sampleRate=*/SAMPLERATE_100, \
/*pulseWidth=*/PULSEWIDTH_411, /*adcRange=*/ADCRANGE_16384);
}
int32_t SPO2; //SPO2
int8_t SPO2Valid; //Flag to display if SPO2 calculation is valid
int32_t heartRate; //Heart-rate
int8_t heartRateValid; //Flag to display if heart-rate calculation is valid
void loop()
{
particleSensor.heartrateAndOxygenSaturation(/**SPO2=*/&SPO2, /**SPO2Valid=*/&SPO2Valid, /**heartRate=*/&heartRate, /**heartRateValid=*/&heartRateValid);
lcd.setCursor(1,0);
lcd.print("BPM: ");
lcd.print(heartRate, DEC);
lcd.print(" ");
lcd.print(" ");
lcd.setCursor(0, 1);
if (heartRateValid == 1){
lcd.print(F("SPO2: "));
lcd.print(SPO2, DEC);
} else if (heartRateValid == 0) {
lcd.print(F("SPO2: 0"));
lcd.print("%");
}
delay(10);
}
Comments
Please log in or sign up to comment.