I'm trying to combine 4 sensors' codes into one to display on the serial monitor: MAX30205, MAX30100, AHT20, and ENS160. I'm using the Adafruit ESP32 Feather V2 board. Here are the libraries that I've used: https://github.com/gabriel-milan/Arduino-MAX30100 https://github.com/Protocentral/Protocentral_MAX30205 https://github.com/DFRobot/DFRobot_AHT20 https://github.com/DFRobot/DFRobot_ENS160 My code compiled and uploaded successfully, but it seems that only the AHT20 and ENS160 display correct data. When I put my finger on the MAX30100 and MAX30205, the sensor data stays at 0 (0 degrees Celsius, 0 bmp, 0% spo2). I need help to see if there's anything I've missed in combining the code. I've tested all the sensors individually and they work fine. This is my code:
#include <DFRobot_ENS160.h>
#include "Protocentral_MAX30205.h"
#include "MAX30100_PulseOximeter.h"
#include <Wire.h>
// Sensor objects
DFRobot_AHT20 aht20;
DFRobot_ENS160_I2C ENS160(&Wire, 0x53);
MAX30205 tempSensor;
PulseOximeter pox;
#define REPORTING_PERIOD_MS 1000
uint32_t tsLastReport = 0;
// Callback for beat detection
void onBeatDetected() {
Serial.println("Beat!");
}
void setup() {
Serial.begin(115200);
Wire.begin();
// Initialize AHT20 sensor
uint8_t status;
while ((status = aht20.begin()) != 0) {
Serial.print("AHT20 sensor initialization failed. Error status: ");
Serial.println(status);
delay(1000);
}
// Initialize ENS160 sensor
while (NO_ERR != ENS160.begin()) {
Serial.println("Communication with ENS160 device failed, please check connection");
delay(3000);
}
ENS160.setPWRMode(ENS160_STANDARD_MODE);
ENS160.setTempAndHum(25.0, 50.0);
// Initialize MAX30205 sensor
while (!tempSensor.scanAvailableSensors()) {
Serial.println("Couldn't find the MAX30205 temperature sensor, please connect the sensor.");
delay(30000);
}
tempSensor.begin();
// Initialize MAX30100 sensor
Serial.print("Initializing pulse oximeter...");
if (!pox.begin()) {
Serial.println("FAILED");
for (;;);
} else {
Serial.println("SUCCESS");
}
pox.setOnBeatDetectedCallback(onBeatDetected);
}
void loop() {
// Collect data from AHT20
if (aht20.startMeasurementReady(true)) {
float temperature = aht20.getTemperature_C();
float humidity = aht20.getHumidity_RH();
Serial.print("AHT2x - Temperature: ");
Serial.print(temperature);
Serial.println(" 'C");
Serial.print("AHT2x - Humidity: ");
Serial.print(humidity);
Serial.println(" %RH");
}
// Collect data from ENS160
uint8_t Status = ENS160.getENS160Status();
uint8_t AQI = ENS160.getAQI();
uint16_t TVOC = ENS160.getTVOC();
uint16_t ECO2 = ENS160.getECO2();
Serial.print("ENS160 - Air quality index: ");
Serial.println(AQI);
Serial.print("ENS160 - Concentration of total volatile organic compounds: ");
Serial.print(TVOC);
Serial.println(" ppb");
Serial.print("ENS160 - Carbon dioxide equivalent concentration: ");
Serial.print(ECO2);
Serial.println(" ppm");
// Collect data from MAX30205
float bodyTemp = tempSensor.getTemperature();
Serial.print("MAX30205 - Body temperature: ");
Serial.print(bodyTemp, 2);
Serial.println(" 'C");
// Collect data from MAX30100
pox.update();
if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
float heartRate = pox.getHeartRate();
float SpO2 = pox.getSpO2();
Serial.print("MAX30100 - Heart rate: ");
Serial.print(heartRate);
Serial.println(" BPM");
Serial.print("MAX30100 - SPO2: ");
Serial.print(SpO2);
Serial.println(" %");
tsLastReport = millis();
}
Serial.println();
delay(1000);
}```
delay(1000)
, move the rest of the code in the loop() with the exception ofpox.update()
into theif (millis() - tsLastReport > REPORTING_PERIOD_MS)
block.