Hi, I am trying to connect 2 ms8607 sensors for reading pressure, humidity and temp to my Arduino Nano Every. However, my code doesn't work for 2 of them. When i connect one there are no issues but with two I get the following output in my Serial Monitor:
Adafruit MS8607 test!
Failed to find MS8607-1 chip
Does anyone know how I can modify my code so it finds my chip?
Here is the code I am uploading:
// Basic demo for reading Humidity and Temperature
#include <Wire.h>
#include <Adafruit_MS8607.h>
#include <Adafruit_Sensor.h>
const int SENSOR_1 = 2; // Pin number for sensor 1
const int SENSOR_2 = 3; // Pin number for sensor 2
Adafruit_MS8607 ms8607_1; // First MS8607 sensor instance
Adafruit_MS8607 ms8607_2; // Second MS8607 sensor instance
bool sensor1Active = true; // Flag to indicate the active sensor
void setup(void) {
Serial.begin(9600);
while (!Serial) delay(10); // will pause Zero, Leonardo, etc until serial console opens
Serial.println("Adafruit MS8607 test!");
// Initialize both sensors
if (!ms8607_1.begin()) {
Serial.println("Failed to find MS8607-1 chip");
while (1) { delay(10); }
}
Serial.println("MS8607-1 Found!");
if (!ms8607_2.begin(0x77)) {
Serial.println("Failed to find MS8607-2 chip");
while (1) { delay(10); }
}
Serial.println("MS8607-2 Found!");
pinMode(SENSOR_1, OUTPUT);
pinMode(SENSOR_2, OUTPUT);
ms8607_1.setHumidityResolution(MS8607_HUMIDITY_RESOLUTION_OSR_8b);
Serial.print("Humidity resolution for sensor 1 set to ");
switch (ms8607_1.getHumidityResolution()){
case MS8607_HUMIDITY_RESOLUTION_OSR_12b: Serial.println("12-bit"); break;
case MS8607_HUMIDITY_RESOLUTION_OSR_11b: Serial.println("11-bit"); break;
case MS8607_HUMIDITY_RESOLUTION_OSR_10b: Serial.println("10-bit"); break;
case MS8607_HUMIDITY_RESOLUTION_OSR_8b: Serial.println("8-bit"); break;
}
ms8607_2.setHumidityResolution(MS8607_HUMIDITY_RESOLUTION_OSR_8b);
Serial.print("Humidity resolution for sensor 2 set to ");
switch (ms8607_2.getHumidityResolution()){
case MS8607_HUMIDITY_RESOLUTION_OSR_12b: Serial.println("12-bit"); break;
case MS8607_HUMIDITY_RESOLUTION_OSR_11b: Serial.println("11-bit"); break;
case MS8607_HUMIDITY_RESOLUTION_OSR_10b: Serial.println("10-bit"); break;
case MS8607_HUMIDITY_RESOLUTION_OSR_8b: Serial.println("8-bit"); break;
}
Serial.println("");
}
void loop() {
if (sensor1Active) {
digitalWrite(SENSOR_1, LOW); // Activate sensor 1
digitalWrite(SENSOR_2, HIGH); // Deactivate sensor 2
sensors_event_t temp1, pressure1, humidity1;
ms8607_1.getEvent(&pressure1, &temp1, &humidity1);
Serial.println("Sensor 1 Data:");
Serial.print("Temperature: "); Serial.print(temp1.temperature); Serial.println(" degrees C");
Serial.print("Pressure: "); Serial.print(pressure1.pressure); Serial.println(" hPa");
Serial.print("Humidity: "); Serial.print(humidity1.relative_humidity); Serial.println(" %rH");
} else {
digitalWrite(SENSOR_1, HIGH); // Deactivate sensor 1
digitalWrite(SENSOR_2, LOW); // Activate sensor 2
sensors_event_t temp2, pressure2, humidity2;
ms8607_2.getEvent(&pressure2, &temp2, &humidity2);
Serial.println("Sensor 2 Data:");
Serial.print("Temperature: "); Serial.print(temp2.temperature); Serial.println(" degrees C");
Serial.print("Pressure: "); Serial.print(pressure2.pressure); Serial.println(" hPa");
Serial.print("Humidity: "); Serial.print(humidity2.relative_humidity); Serial.println(" %rH");
}
Serial.println("");
sensor1Active = !sensor1Active; // Toggle the active sensor
delay(500);
}
Thanks a lot in advance.