Hi! I'm trying to use an Arduino Uno R4 Wifi with a pulse heart rate DAOKAI MAX30102. In Arduino IDE, I use this script and it works:
giusto_range_di_valori.ino (2,0 KB)
Anyway, when I try to use it in the IoT Cloud, there's an error in the sensor library. It seems not to use SparkFun MAX3010x Pulse and Proximity Sensor Library, but in the IoT Cloud I can't force it to use it because I can't manage the libraries.
This is the script I use in IoT Cloud:
#include <MAX30105.h> // Usa la libreria SparkFun
#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>
// Definisci le tue credenziali Wi-Fi (configurazione su Arduino IoT Cloud)
const char SSID[] = SECRET_SSID; // Dati definiti nel pannello IoT Cloud
const char PASS[] = SECRET_OPTIONAL_PASS; // Dati definiti nel pannello IoT Cloud
MAX30105 particleSensor; // Sensore di particelle
// Variabili cloud
float beatAvg; // Frequenza cardiaca media da inviare al cloud
// Funzione per il setup della connessione Wi-Fi e Cloud
WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);
void initCloud() {
// Inizializza il cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2); // Livello di debug
ArduinoCloud.printDebugInfo(); // Stampa informazioni di debug
}
// Funzione per gestire i cambiamenti della variabile beatAvg
void onBeatAvgChange() {
// Funzione chiamata quando il valore di beatAvg cambia nel cloud
}
// Configura le variabili del cloud
void initVariables() {
ArduinoCloud.addProperty(beatAvg, READ, 5 * SECONDS, onBeatAvgChange);
}
// Funzione per rilevare il battito
bool checkForBeat(long irValue) {
static long lastValue = 0;
if (irValue > 50000 && irValue > lastValue + 1000) {
lastValue = irValue;
return true;
}
lastValue = irValue;
return false;
}
void setup() {
Serial.begin(115200);
Serial.println("Inizializzazione...");
// Inizializza il cloud e variabili
initCloud();
initVariables();
// Inizializza il sensore
if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) {
Serial.println("MAX30102 non trovato. Controlla i collegamenti.");
while (1);
}
Serial.println("Posiziona il dito sul sensore.");
// Configura il sensore
particleSensor.setup();
particleSensor.setPulseAmplitudeRed(0x0A); // Attiva il LED rosso
particleSensor.setPulseAmplitudeGreen(0); // Disattiva il LED verde
}
void loop() {
ArduinoCloud.update(); // Aggiorna il cloud
long irValue = particleSensor.getIR(); // Ottiene il valore del sensore IR
if (checkForBeat(irValue)) {
long delta = millis() - last_beat;
last_beat = millis();
float bpm = 60 / (delta / 1000.0);
if (bpm < 255 && bpm > 20) {
beatAvg = bpm; // Aggiorna il valore medio
Serial.print("BPM: ");
Serial.println(beatAvg);
}
}
if (irValue < 50000) {
beatAvg = -1;
}
}
Hi @iridargyros. I'll provide instructions you can follow to configure the library that should be used when compiling your sketch in Arduino Cloud:
-
If you are not already, log in to your Arduino account:
https://login.arduino.cc/login
-
Click the following link to open the list of your Arduino Cloud sketches in the web browser:
https://app.arduino.cc/sketches
-
Select the sketch for which you want to configure the library to be used.
The sketch will open in Arduino Cloud Editor.
-
Click the icon that looks like shelved books ("Libraries") in the bar on the left side of the Cloud Editor page.
The "Libraries" panel will open.
-
Type SparkFun MAX3010x Pulse and Proximity Sensor Library
in the "Search libraries" field near the top of the panel.
-
You will see text under the "Search libraries" field:
Show libraries for:
<board name>
(where <board name> is the name of the board you have selected in Cloud Editor)
Click the board name in that text.
The text will now change to:
Show libraries for:
ALL DEVICES
-
Scroll down through the list of libraries until you find the entry for the "SparkFun MAX3010x Pulse and Proximity Sensor Library" library.
-
You will see a dropdown menu in the library's entry. Click on it.
The menu will open.
-
Select the version of the library you want the sketch to use from the menu.
You must select a menu item other than the "Latest (...)" item at the top of the menu.
The menu will close.
-
Click the "INCLUDE" button in the "" library entry.
ⓘ Clicking this button configures the sketch to use the "" library, at the specific version selected from the menu.
You might now see a "Library already included" notification. This is expected and doesn't indicate any problem.
-
As an irrelevant side effect, one or more #include
directives may have been added to the sketch. These newly added directives will only clutter up your sketch and might even cause problems, so delete those lines from the sketch.
Now try compiling the sketch again. This time the expected library should be used.
Note that the library configuration achieved via the above procedure was specific to the sketch you had open in Arduino Cloud Editor. If you want to make the same configuration for another sketch, open it in Cloud Editor and repeat the procedure.
The above procedure configured the sketch to always use the version you selected from the menu. Important enhancements or bug fixes might be made to the library in future releases of the library, so it is a good idea to periodically check for the availability of newer versions. You can repeat the procedure above to configure the sketch to use a different version of the library.
Please let me know if you have any questions or problems while following those instructions.
Hi! I followed your procedure a couple of times, and it went well, but every time I try to change something in the code to run tests, that error occurs. I also tried creating a new sketch and redoing the procedure, but nothing works. How can I fix this?
The error:
/usr/local/bin/arduino-cli compile --fqbn arduino:renesas_uno:unor4wifi --build-cache-path /tmp --output-dir /tmp/2392642614/build --build-path /tmp/arduino-build-2A96CA74E93337B9D27BF7EF1F1200F9 /tmp/2392642614/beatAvg_oct02a
/home/builder/Arduino/libraries/emotibit_max30101_2_0_3/src/heartRate.cpp:61:10: fatal error: Filters/Butterworth.hpp: No such file or directory
#include <Filters/Butterworth.hpp>
^~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Multiple libraries were found for "MAX30105.h"
Used: /home/builder/opt/libraries/emotibit_max30101_2_0_3
Not used: /home/builder/opt/libraries/max3010x_sensor_library_1_0_5
Not used: /home/builder/opt/libraries/sparkfun_max3010x_pulse_and_proximity_sensor_library_1_1_2
Multiple libraries were found for "Filters.h"
Used: /home/builder/opt/libraries/filters_0_1_2
Not used: /home/builder/opt/libraries/dspfilters_0_2_2
Not used: /home/builder/opt/libraries/emotibit_arduinofilters_1_0_0
Not used: /home/builder/opt/libraries/strawbees_quirkbot_2_10_0
Multiple libraries were found for "RTC.h"
Used: /home/builder/.arduino15/packages/arduino/hardware/renesas_uno/1.2.1/libraries/RTC
Not used: /home/builder/opt/libraries/m5stickc_0_3_0
Not used: /home/builder/opt/libraries/m5stickcplus_0_1_0
Not used: /home/builder/opt/libraries/m5core2_0_1_9
Not used: /home/builder/opt/libraries/m5station_0_0_1
Multiple libraries were found for "Wire.h"
Used: /home/builder/.arduino15/packages/arduino/hardware/renesas_uno/1.2.1/libraries/Wire
Not used: /home/builder/opt/libraries/flexwire_1_2_1
Error during build: exit status 1
I'm sorry to hear that. Please provide the updated sketch code that produces the error and I'll investigate..
Thanks. I tried it and it does produce a compilation error, but the error is different from the one you posted:
/tmp/2661205610/beatAvg_oct03a/beatAvg_oct03a.ino:17:7: error: redefinition of 'float beatAvg'
float beatAvg;
^~~~~~~
In file included from /tmp/2661205610/beatAvg_oct03a/beatAvg_oct03a.ino:3:0:
/tmp/2661205610/beatAvg_oct03a/thingProperties.h:11:7: note: 'float beatAvg' previously declared here
float beatAvg;
^~~~~~~
This error is expected due to a basic bug in your sketch. Arduino Cloud automatically adds a declaration for each of the IoT Variables to the thingProperties.h
file that is generated in the sketch. For some reason, you added a redundant declaration for the variable in the beatAvg_oct02a.ino
sketch file, which causes this "redefinition of 'float beatAvg'
" error.
I fixed the bug by removing line 16 from beatAvg_oct02a.ino
:
float beatAvg;
After that, the compilation was successful.
I can see from this line of the compilation output that the procedure did not work. The procedure I provided in post #2 should have resulted in the addition of this flag to the command:
--library /home/builder/opt/libraries/sparkfun_max3010x_pulse_and_proximity_sensor_library_1_1_2
Please try performing the procedure once more, making sure to follow every step precisely. Note that it is essential to select the "1.1.2" item from the menu instead of the "Latest (1.1.2)" item at step (9) of the instructions.
Hopefully doing that will cause Arduino Cloud to use the intended library. If not, let me know and I'll provide instructions for an alternative technique.