I am trying to interface the MAX30100 and MAX30102 sensors with my Arduino Nano 33 IOT board. I am using the Arduino IOT Cloud for visualising my data. I am not getting any HR or spo2 values on the serial monitor, it always returns zero, except for a few instances when it randomly returns a few beats. The example I am using is "MAX30100_minimal" and it works perfectly with the Arduino IDE. I have attached the code I am uploading while using it with the cloud.
// MAX30100lib - Version: Latest
//#include <CircularBuffer.h>
//#include <MAX30100.h>
//#include <MAX30100_BeatDetector.h>
//#include <MAX30100_Filters.h>
#include <MAX30100_PulseOximeter.h>
//#include <MAX30100_Registers.h>
//#include <MAX30100_SpO2Calculator.h>
#include <Wire.h>
#define REPORTING_PERIOD_MS 1000
// Arduino Cloud Provider Examples - Version: 1.2.0
#include <ArduinoCloudProviderExamples.h>
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/e09ce2cd-218a-4e53-8e09-49da0c9ed269
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
CloudPercentage spo2;
CloudHeartRate heartBeat;
CloudTemperature temperature;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
PulseOximeter pox;
//MAX30100 sensor;
uint32_t tsLastReport = 0;
// Callback (registered below) fired when a pulse is detected
void onBeatDetected()
{
Serial.println("Beat!");
}
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
//delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(3);
ArduinoCloud.printDebugInfo();
Serial.print("Initializing pulse oximeter..");
// 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");
}
// The default current for the IR LED is 50mA and it could be changed
// by uncommenting the following line. Check MAX30100_Registers.h for all the
// available options.
// pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
// Register a callback for the beat detection
pox.setOnBeatDetectedCallback(onBeatDetected);
}
void loop() {
ArduinoCloud.update();
// Your code here
// Make sure to call update as fast as possible
pox.update();
if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
heartBeat = pox.getHeartRate();
spo2 = pox.getSpO2();
temperature = 32;
Serial.print("Heart rate:");
Serial.print(heartBeat);
Serial.print("bpm / SpO2:");
Serial.print(spo2);
Serial.print("% / temperature:");
Serial.print(temperature);
Serial.println("degC");
tsLastReport = millis();
}
/*
heartBeat = random(300,600);
spo2 = random(94,98);
temperature = random(25,35);
Serial.println(spo2)
*/
}
I tried printing random values for the variables and they were correctly printed on the serial monitor as well as on the cloud. There is some issue with the onBeatDetected() function, it is not getting called for some reason. Please Guide.