I’m using BMP280 and MAX30100 with XIAO ESP32 C3. Data for BMP280 shows on serial monitor and also on BLYNK but for MAX30100, it shows 0 for both values. They work separately but not togather.
here’s the library link for max30100 link
here’s the code:
* Fill-in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID " "
#define BLYNK_DEVICE_NAME " "
#define BLYNK_AUTH_TOKEN " "
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32_SSL.h>
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#include <ErriezBMX280.h>
BlynkTimer timer;
#define REPORTING_PERIOD_MS 1000
#define SEA_LEVEL_PRESSURE_HPA 1026.25
// PulseOximeter is the higher level interface to the sensor
// it offers:
// * beat detection reporting
// * heart rate calculation
// * SpO2 (oxidation level) calculation
PulseOximeter pox;
ErriezBMX280 bmx280 = ErriezBMX280(0x76);
float HR, SpO2;
float temp, alt;
uint32_t tsLastReport = 0;
//// Set password to "" for open networks.
char ssid[] = "Mughals";
char pass[] = "mughals2343";
// Callback (registered below) fired when a pulse is detected
void onBeatDetected()
{
Serial.println("Beat!");
}
void setup()
{
Serial.begin(115200);
Serial.print("Initializing pulse oximeter..");
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
// Initialize the PulseOximeter instance
// Failures are generally due to an improper I2C wiring, missing power supply
// or wrong target chip
if (!pox.begin()) {
Serial.println("FAILED");
for (;;);
} else {
Serial.println("SUCCESS");
}
// Register a callback for the beat detection
pox.setOnBeatDetectedCallback(onBeatDetected);
pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
Wire.begin();
Wire.setClock(400000);
// Initialize BMX280 sensor
while (!bmx280.begin()) {
Serial.println(F("Error: Could not detect BMX280 sensor"));
delay(3000);
}
// Set sampling for BMX280 sensor
bmx280.setSampling(BMX280_MODE_NORMAL, BMX280_SAMPLING_X16, BMX280_SAMPLING_X16, BMX280_SAMPLING_X16, BMX280_FILTER_X16, BMX280_STANDBY_MS_500);
timer.setInterval(1000L, bmp);
timer.setInterval(1000L, mx);
delay(100);
}
void mx()
{
HR = pox.getHeartRate();
SpO2 = pox.getSpO2();
if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
Serial.print("Heart rate:");
Serial.print(HR);
Serial.print(" bpm / SpO2:");
Serial.print(SpO2);
Serial.println("%");
Blynk.virtualWrite(V1, SpO2);
Blynk.virtualWrite(V4, HR);
tsLastReport = millis();
}
}
void bmp()
{
temp = bmx280.readTemperature();
alt = bmx280.readAltitude(SEA_LEVEL_PRESSURE_HPA);
Serial.print("Temperature: ");
Serial.print(temp);
Serial.println(" C");
Serial.print("Altitude: ");
Serial.print(alt);
Serial.println(" m");
Serial.println();
Blynk.virtualWrite(V2, temp);
Blynk.virtualWrite(V3, alt);
}
void loop()
{
// Make sure to call update as fast as possible
pox.update();
Blynk.run();
timer.run();
}
here’s the serial monitor output:
ESP-ROM:esp32c3-api1-20210207
Initializing pulse oximeter…[168] Connecting to Mughals
[3706] Connected to WiFi
[3706] IP: 192.168.10.8
[3706]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ / '/
///_, /////_
/__/ v1.2.0 on ESP32
#StandWithUkraine https://bit.ly/swua
[3707] Connecting to blynk.cloud:443
[4713] Certificate OK
[4907] Ready (ping: 193ms).
SUCCESS
Temperature: 33.16 C
Altitude: 302.69 m
Heart rate:0.00 bpm / SpO2:0.00%
Temperature: 33.16 C
Altitude: 302.62 m
Temperature: 33.15 C
Altitude: 302.57 m