Connect two BME280 Sensors on the I2C bus


Did you know that the BME280 sensor has two different I2C addresses? That means, you can read two BME280 sensors at the same time on the I2C bus. One sensor will use the default address (0x77) and the other sensor will use the alternative address (0x76).

 

First, let's connect the sensors like this:

  • VCC pin from both sensors to either 3.3V or 5V. If you are using an Arduino Uno, use the 5V pin.
  • GND pin from both sensors to the GND pin on your Arduino.
  • SCK pin from both sensors to the I2C clock SCL pin on your Arduino. On the Arduino Uno that would be the pin A5.
  • SDI pin from both sensors to the I2C data SDA pin on your Arduino. On the Arduino Uno that would be the pin A4.
  • Leave the CS pin from both sensors unconnected.
  • Leave the SDO pin from only one sensor unconnected.
  • Connect the SDO pin from the other sensor to GND.

When you leave the SDO pin from one sensor unconnected, you are telling this sensor to use the default I2C address (0x77).

But when you connect the SDO pin from the second sensor to GND, you are telling it to use the alternative I2C address (0x76).

Now we need the software. If you did not do this yet, download and install the BlueDot BME280 library through the Arduino IDE. This is important, because the BlueDot library does work with two BME280 sensors on the I2C bus.

 


Not every library for the BME280 available on the internet works with two sensors on the I2C bus. Just to be safe, download and install the BlueDot BME280 library.

Just go to Sketch -> Include Library -> Manage Libraries... and search for the BlueDot BME280 Library. Now click on it and install the library. You can also visit the GitHub repository to download the latest version of the library or just click on this button bellow.

After installing the library, run the example for multiple sensors on the I2C bus. Open up File -> Examples -> BlueDot_BME280_library -> BME280_MultipleSensorsI2C.

After uploading the code into your Arduino,  open up the Serial Monitor at 9600 baud speed to get the temperature, humidity, pressure and altitude from both sensors at the same time.

The functions for each sensor are slightly different. At the beginning of the program you declare two objects bme1 and bme2, one for each sensor. We need those to keep the calibration parameters for each sensor separated from each other.

 


    BlueDot_BME280 bme1;                                     //Object for Sensor 1
    BlueDot_BME280 bme2;                                     //Object for Sensor 2

Now, the functions starting with bme1 refers to the first sensor, while the functions starting with bme2 refers to the second sensor.

 


    Serial.println(bme1.readTempC());
    Serial.println(bme1.readTempF());
    Serial.println(bme1.readHumidity());
    Serial.println(bme1.readPressure());
    Serial.println(bme1.readAltitudeMeter());
    Serial.println(bme1.readAltitudeFeet());
   
    Serial.println(bme2.readTempC());
    Serial.println(bme2.readTempF());
    Serial.println(bme2.readHumidity());
    Serial.println(bme2.readPressure());
    Serial.println(bme2.readAltitudeMeter());
    Serial.println(bme2.readAltitudeFeet());

xkcd.com

Comments

Please tell us what you think about our website and our products. We welcome your comments and suggestions.

Comments: 2
  • #2

    BlueDot (Wednesday, 06 June 2018 00:07)

    Hello David!

    adding a third board through the SPI interface shouldn't influence the first two boards on the I2C bus, because the pullup resistors from from the third board would be connected either to a digital pin (Software-SPI) or to the MOSI/MISO pin on the ICSP header (Hardware-SPI). Either way, the pullup resistors from the two boards on the I2C bus are connected to the SDA and SCL pins and wouldn't be in parallel to the resistors from the third board. So no problems there!

    Disabling or removing any pullup resistors from a board would be a problem, because these resistors are part of the logic level shifting circuit and you would basically interrupt the communication to the sensors. Doing this would be really messy and I wouldn't recommend it. Instead, a better solution would be to use an I2C expander breakout board, like the TCA9548A offered by Adafruit. It is dirty cheap and allows you to connect up to eight boards on a single I2C address, while keeping each I2C bus isolated from each other.

    Hope this could answer your question! :)

  • #1

    David Tucker (Monday, 04 June 2018 10:08)

    Thank you so much for the dual I2C connections tutorial and library for the BME280. I am now able to see the fluctuations of two sensors wrrt time. I will now try adding a third using the SPI interface to further improve the stablity of the pressure measurement.

    I suppose when I have two of these boards on the I2C bus I have half the pullup resistance. Do you have any advice regarding disabling the pullups on your boards if this poses an issue with multiple sensors on the I2C bus?

    Thanks

    David