The MAX30100 pulse oximeter won't read values if the line 'ArduinoCloud.update()' is in the loop. However, the analog LM35 temperature sensor reads values.
Why does it display such a behaviour?
I have to mention that I get this warning every time I compile the code:
'WARNING: library ArduinoIoTCloud claims to run on mbed, samd, esp8266, mbed_nano, mbed_portenta, mbed_nicla architecture(s) and may be incompatible with your current board which runs on esp32 architecture(s).'
Questions: Could this be the problem? Should I change the microcontroller for ESP8266 even though the IoT platform supposedly supports ESP32? I have tried compiling it through the Arduino IoT Cloud platform (IoT Editor) - which is done requiring the Arduino Cloud Agent. I received the same message. The connection takes place, but no changes whatsoever / no reading of values, not on the Serial Monitor, nor on the display value of the created and attached widgets.
Some more questions: How would one approach this problem? Should I change the platform? The sensors work just fine if I remove / comment 'ArduinoCloud.update()'.
Here is the main code
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/d8c4c097-310c-4872-8624-25458eafb1e6
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
float heart_rate_cloud;
float spO2_cloud;
CloudTemperatureSensor temp;
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 "arduino_secrets.h"
#include "thingProperties.h"
#include <OneWire.h>
#include "MAX30100_PulseOximeter.h"
#include <Wire.h>
#define REPORTING_PERIOD_MS 1000
PulseOximeter pox; //we will be calling Pulseoximeter as pox
#define ADC_VREF_mV 3300.0 // in millivolt
#define ADC_RESOLUTION 4096.0
#define PIN_LM35 33
uint32_t tsLastReport = 0;
void onBeatDetected()
{
Serial.println("Beat Detected!");
}
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(2);
ArduinoCloud.printDebugInfo();
Serial.print("Initializing Pulse Oximeter..");
if (!pox.begin())
{
Serial.println("FAILED");
for (;;);
}
else
{
Serial.println("SUCCESS");
pox.setOnBeatDetectedCallback(onBeatDetected);
}
pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
}
void loop() {
ArduinoCloud.update();
// Your code here
SENSORS_READ();
}
void SENSORS_READ() {
pox.update();
if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
float heart_rate_cloud = pox.getHeartRate();
float spO2_cloud = pox.getSpO2();
Serial.print("Heart rate:");
Serial.print(pox.getHeartRate());
Serial.print("bpm / SpO2:");
Serial.print(pox.getSpO2());
Serial.println("%");
// read the ADC value from the temperature sensor
int adcVal = analogRead(PIN_LM35);
// convert the ADC value to voltage in millivolt
float milliVolt = adcVal * (ADC_VREF_mV / ADC_RESOLUTION);
// convert the voltage to the temperature in °C
float tempC = milliVolt / 10 + 20.5;
// convert the °C to °F
float tempF = tempC * 9 / 5 + 32;
// print the temperature in the Serial Monitor:
Serial.print("Temperature: ");
Serial.print(tempC); // print the temperature in °C
Serial.print("°C");
tsLastReport = millis();
}
}
I have tried using normally declared float values in the code instead of cloud generated values and still no readings occured.
Here is the thingsProprietes.h code:
// Code generated by Arduino IoT Cloud, DO NOT EDIT.
#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>
const char DEVICE_LOGIN_NAME[] = "long-id-many-numbers-and-letters";
const char SSID[] = SECRET_SSID; // Network SSID (name)
const char PASS[] = SECRET_PASS; // Network password (use for WPA, or use as key for WEP)
const char DEVICE_KEY[] = SECRET_DEVICE_KEY; // Secret device password
float heart_rate_cloud;
float spO2_cloud;
CloudTemperatureSensor temp;
void initProperties(){
ArduinoCloud.setBoardId(DEVICE_LOGIN_NAME);
ArduinoCloud.setSecretDeviceKey(DEVICE_KEY);
ArduinoCloud.addProperty(heart_rate_cloud, READ, ON_CHANGE, NULL);
ArduinoCloud.addProperty(spO2_cloud, READ, ON_CHANGE, NULL);
ArduinoCloud.addProperty(temp, READ, ON_CHANGE, NULL);
}
WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);