OK, now let's try using two BME280s. Now there's some work to do. Both the hardware and the code will need to be changed.

Both BME280s can't use the default address of 0x77. Not all devices have this capability, but the BME280 allows setting a second I2C address ox 0x76. That allows for the following connection:

But how did we know the alternate address was 0x76? And how was the breakout altered to set the address to 0x76?

Finding and Setting Alternate Addresses

How do you know if any given device has the ability to set an alternate I2C address? Ideally, it will be mentioned in the product guide or some other documentation. Sometimes this may required digging into the device's datasheet. Also, since the most common method of setting the alternate address is by using additional pins, there are some physical features to look for on any given breakout. For example, the BME280 has a solder pad for setting the alternate address on the backside of the board:

If nothing is done, the BME280 has the indicated default address of 0x77. By adding a blob of solder to electrically connect to the two copper pads, the alternate address of 0x76 is set. Here is what a blob of solder on the address jumper pad looks like:

Another place to look would be the row of header pins. For example, the ADS1105 and ADS1115 ADC breakouts have a dedicated pin for setting the alternate address.

This is done since setting alternate addresses for the ADS1015/1115 is not as simple as making/breaking a single connection - which is what solder pad jumpers are used for. A total of four different addresses can be set depending on what the ADDR pin is connected to.

Trying to do that with solder jumpers would be a bit of a mess.

Coding for Alternate Address Usage

Once the hardware has been modified to set an alternate I2C address, what are the required code changes? To use an alternate, non-default address, it must be explicitly called out in user code. But exactly where and how is that done? It's different for Arduino and CircuitPython.

Arduino

For Adafruit Arduino libraries, the alternate address is passed in when calling begin() on the sensor object. This code is typically placed in an Arduino sketch's setup() function. For example, to specify the alternate address of 0x76 for the BME280:

bme.begin(0x76);  // specify the alternate address of 0x76
In Arduino, FOR MOST LIBRARIES, you can specify the I2C address in the call to the device's begin() library function.

NOTE: There can be some library-to-library variability in the specific format for calling begin(). So be sure to look at the associated library documents.

CircuitPython

For Adafruit CircuitPython libraries, the alternate address is passed in when creating the instance for the sensor. For example, to specify the alternate address of 0x76 for the BME280:

bme = adafruit_bme280.Adafruit_BME280_I2C(i2c, 0x76)
In CircuitPython, specify the I2C address as a parameter when creating the device instance.

NOTE: Sometimes a parameter name, like addr or address is used.

Consult The List

The following guide attempts provide a list of I2C addresses for popular I2C devices:

There are a lot. One could text search on that page and see if a given device is there. For example, search for "BME280" to find the entry:

And now it's known that the BME280 can have an I2C address of either 0x76 or 0x77.

However, this list requires manually updating. So the page may or may not have the sensor you're looking for.

When In Doubt, Scan

Running an I2C scan is a good way to sanity check the setup. Not only will it report the I2C addresses for all discovered devices, it's also a good way to verify the I2C connections themselves are OK. There's a dedicated guide on I2C scanning here:

There are examples for scanning with Arduino, CircuitPython, and on Raspberry Pi. Here is what typical Arduino scan output looks like:

There's something at 0x76 and 0x77! That's the two BME280 breakouts as shown in the wiring diagram above. One is unaltered and has an I2C address of 0x77. One has the solder jumper closed and has an I2C address of 0x76.

This guide was first published on May 04, 2022. It was last updated on May 04, 2022.

This page (Two Devices using Alternate Address) was last updated on May 24, 2022.

Text editor powered by tinymce.