Now to look at using three BME280s. There are no easy options, since the BME280 only has two available I2C addresses. So now to introduce the TCA9548A I2C multiplexer. Also, to help illustrate the use of the TCA9548A, this will ignore the BME280's alternate address. Therefore, this example is exactly like what one would deal with when trying to use three copies of any I2C device with a single fixed address.

Here is the wiring diagram for the setup. Note that the TCA9548A itself has an I2C address of 0x70. Each BME280 has the same address of 0x77.

The TCA9548A Multiplexer

This is a simple device. It has only one trick up its sleeve. It has one input and eight outputs. The only I2C "command" it accepts is one to set what outputs are active. That's it. That's all it does.

It is an I2C device though, so does have an I2C address. The address can be changed, but in this guide we'll only use its default 0x70 address. No other device can have the same address as the TCA9548A. So the basic rule about unique addresses still applies.

Changing Output Channels

While the TCA9548A can have more than one output channel active at a time, this only considers using a single channel at a time. The one "command" that the TCA9548A accepts is a single byte value, where each bit represents an output channel:

If the bit is 1, the channel is active. If the bit is 0, the channel is not active. Super simple.

The easiest way to generate the proper byte to activate a single channel is to left shift 1 by the channel number. An example Arduino code snippet to do this would look like:

Wire.beginTransmission(TCA_ADDRESS);
Wire.write(1 << CHANNEL_NUMBER);
Wire.endTransmission();

Where TCA_ADDRESS would be the 0x70 (or other) address of the TCA9548A and CHANNEL_NUMBER would be an integer value 0 to 7 for the desired output channel. The << is the left shift operator.

This is the exact same code as shown in the TCA9548A guide and will also be used here in the Arduino examples. There is no dedicated Arduino library for the TCA9548A. Channel switching must be done manually in Arduino sketch code.

When using CircuitPython, things are a little fancier. There is a CircuitPython library for the TCA9548A. Under the hood, it's no different than the Arduino example above. The left shifting can be seen here. The neat thing about the CircuitPython library is that it can take care of sending the channel switch byte to the TCA9548A automatically.

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

This page (Three Devices using Multiplexer) was last updated on May 20, 2022.

Text editor powered by tinymce.