I'm using a ESP32 microcontroller, and sensors connected to different SDA & SCL pins MAX30100 (21, 22), MPU6050 (32, 33) and MLX90614 (13, 14).
But I don't know how to read data from the sensors.
This is the code I use to run in Arduino IDE I verified it and didn't get any errors but when I uploaded the code to the esp32 and looked at the serial monitor it doesn't show the data.
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#include <Adafruit_MLX90614.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#define REPORTING_PERIOD_MS 1000
TwoWire I2Ctmp = TwoWire(0);
TwoWire I2Cspd = TwoWire(1);
TwoWire I2Cpox = TwoWire(2);
Adafruit_MLX90614 tmp = Adafruit_MLX90614(); //0x5A
Adafruit_MPU6050 spd = Adafruit_MPU6050(); //0x68
PulseOximeter pox; //0x57
// Time at which the last beat occurred
uint32_t tsLastReport = 0;
// Callback routine is executed when a pulse is detected
void onBeatDetected() {
Serial.println("♥ Beat!");
}
void setup() {
Serial.begin(115200);
Serial.print("Initializing pulse oximeter..");
pox.begin();
pox.setOnBeatDetectedCallback(onBeatDetected);
I2Ctmp.begin(13, 14, 100000);
I2Cspd.begin(32, 33, 100000);
tmp.begin(0x5A, &I2Ctmp);
spd.begin(0x68, &I2Cspd);
Serial.println();
}
void loop() {
// Read from the sensor
pox.update();
// Grab the updated heart rate and SpO2 levels
if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
Serial.print("Heart rate:");
Serial.print(pox.getHeartRate());
Serial.print("bpm / SpO2:");
Serial.print(pox.getSpO2());
Serial.println("%");
tsLastReport = millis();
}
Serial.print("Ambient temperature = ");
Serial.print(tmp.readAmbientTempC());
Serial.print("°C");
Serial.print(" ");
Serial.print("Object temperature = ");
Serial.print(tmp.readObjectTempC());
Serial.println("°C");
Serial.print("Ambient temperature = ");
Serial.print(tmp.readAmbientTempF());
Serial.print("°F");
Serial.print(" ");
Serial.print("Object temperature = ");
Serial.print(tmp.readObjectTempF());
Serial.println("°F");
sensors_event_t a, g, temp;
spd.getEvent(&a, &g, &temp);
Serial.print("Accelerometer ");
Serial.print("X: ");
Serial.print(a.acceleration.x, 1);
Serial.print(" m/s^2, ");
Serial.print("Y: ");
Serial.print(a.acceleration.y, 1);
Serial.print(" m/s^2, ");
Serial.print("Z: ");
Serial.print(a.acceleration.z, 1);
Serial.println(" m/s^2");
Serial.print("Gyroscope ");
Serial.print("X: ");
Serial.print(g.gyro.x, 1);
Serial.print(" rps, ");
Serial.print("Y: ");
Serial.print(g.gyro.y, 1);
Serial.print(" rps, ");
Serial.print("Z: ");
Serial.print(g.gyro.z, 1);
Serial.println(" rps");
Serial.println("-----------------------------------------------------------------");
delay(1000);
}