How to connect 2 MS8607 sensors to Arduino nano every

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.

You can't - it's a hardware issue!

The I2C bus requires that each & every device must have a distinct address - but it seems that the ms8607 has no option to change its addresses. :frowning_face:

Are you stuck with this sensor? Many other sensors are available which do have changeable addresses.

Otherwise, you're going to have to use either two I2C buses, or add an I2C mulitplexer...

It won't even work if I would temporarily turn off one of the sensor and read the data from the other one and vice versa?

That could work.

you'd have to ensure that "turning off" the sensor didn't block the I2C bus ...

any suggestion on how i can make sure that this doesn't block the i2c bus?

How were you planning on turning it off?
A relay?

An I2C multiplexer seems the obvious solution!
It is effectively just a switch which connects either one sensor or the other to the I2C bus

See this recent thread - it covers the same issue of using 2 sensors having the same addresses:

There are links to a couple of tutorials on using an I2C Multiplexer...

Use Software I2C

2 Likes

That would be a good way to add a 2nd I2C bus - without needing any extra hardware :+1: :smile:

@capke99 - So you'd keep one sensor on the current (hardware) I2C bus, and move the other sensor to the new (software) I2C bus

Alright, thanks a lot to everyone, I will try this.

1 Like

As always, take one step at a time - don't try to do everything at once!

it sounds like you already have the hardware I2C working alone with one sensor?

so the next step would be to get the software I2C working alone with one sensor.

then - and only then - move on to getting both the hardware and the software I2Cs working together.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.