DS3231 with two BME280

Hi,

I have a project where I need DS3231 and two BME280. My code is as follows. I get message "Couldn't find RTC". Any ideas what is wrong? When I test only RTC with Arduino example codes, it works well, so the problem is assumed to be in code with BME's.

#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include "RTClib.h"

Adafruit_BME280 bme;
#define SDA_1 27
#define SCL_1 26

#define SDA_2 13
#define SCL_2 14


TwoWire I2Cone = TwoWire(0);
TwoWire I2Ctwo = TwoWire(1);

Adafruit_BME280 bme1;
Adafruit_BME280 bme2;

RTC_DS3231 rtc;


void setup() {

  Serial.begin(115200);
  delay(500);
  Serial.println(F("BME280 and Ds3231 test"));
  delay(1000);

  I2Cone.begin(SDA_1, SCL_1, 100000); 
  I2Ctwo.begin(SDA_2, SCL_2, 100000);

  Wire.begin();

  delay(1000);

  bool status1 = bme1.begin(0x76, &I2Cone);
    if (!status1) {
    Serial.println("Could not find a valid BME280_1 sensor, check wiring!");
    digitalWrite(32, HIGH);
    return;
  }  else {
    Serial.println("BME1 sensor found");
    digitalWrite(32, LOW);
  }

bool status2 = bme2.begin(0x76, &I2Ctwo);
    if (!status2) {
    Serial.println("Could not find a valid BME280_2 sensor, check wiring!");
    digitalWrite(32, HIGH);
    return;
  }  else {
    Serial.println("BME2 sensor found");
    digitalWrite(32, LOW);
  }

if (!rtc.begin()) {
    Serial.println("Couldn't find RTC");
    Serial.flush();
    while (1) delay(10);

  }
  else {
    Serial.println("RTC found");
      }
    delay(2000);

}
void loop() {
  
}

what host microcontroller are you using?
which I2C interface is the RTC connected to?
try specifying the I2C interface, e.g.

if (!rtc.begin(&I2Cone)) {

I use ESP32 and ESP's nominal I2C interface is used for RTC (SCL pin 22 and SDA pin 21)

what microcontroller are you using that has three I2C interfaces?

It is possible to define more I2C interfaces to ESP32. It has only one as default, but other pins is possible to define I2C.

as far as I am aware the ESP32 has two I2C hardware interfaces - see ESP32 Comparison chart
a BME280 and RTC should be able to share an I2C interface
otherwise look at a software I2C interface

You only need one I2C for your bme sensors if you change address of one of them to 0x77

I have BMP280 chips without the address jumper settings. They are these ones

The SDO pin sets the address lsb to either 0x76 or 0x77.
On one, connect the SDO to GND and the other to V+.

They have pulldown on SDO, so if you connect it to high (3.3V), it setting address to 0x77

Thanks a lot for your tip! Now it works and I can use the default I2C pins.

Thanks a lot for your tip!

That is the standard Bosch interface. SDO controls the lsb. Almost all are 0x76 and 0x77.
BMP280
BME280
BMP680
BMP390