Sub topic 11
Resolving I2C Address Conflicts with Address Pins and Multiplexers
Assume you know basic Arduino sketches, hexadecimal numbers, and the Wire library. This chapter focuses on a common problem: two I2C devices have the same address.
Why address conflicts happen
Every I2C target uses a 7-bit address. The controller sends this address at the start of a transaction. Only the target with that address should acknowledge and respond.
Many devices have address pins or solder jumpers. These pins select one of a few allowed addresses. For example, a sensor might support 0x68 when its address pin is low and 0x69 when the pin is high.
| Method | Best use | Main limitation |
|---|---|---|
| Address pin or jumper | A small number of identical devices | Only the listed alternate addresses are available |
| I2C multiplexer | Several devices with the same address | Adds a control step and another device on the bus |
| Separate bus | Complete electrical isolation | Requires another controller bus or hardware interface |
An address conflict occurs when two active targets respond to the same address on the same bus. They may both acknowledge, drive different data, or interfere with each other. The controller can then receive corrupted or unpredictable results.
Use address pins first
Check the device data sheet before wiring. It will identify the address pin and show the valid address choices. Connect the pin to the required logic level, or change a solder jumper if the board provides one.
After changing an address, run an I2C scanner. Verify that each device appears at a different address before using its library.
Use a TCA9548A multiplexer
An I2C multiplexer divides one controller bus into separate downstream channels. A TCA9548A has eight channels. The controller first sends a byte to the multiplexer, enabling one channel. It can then communicate with a sensor on that channel.
The multiplexer itself has an address, commonly 0x70. Its address pins can change that value if several multiplexers share the main bus.
This helper enables one channel:
#include <Wire.h>
const uint8_t MUX_ADDRESS = 0x70;
const uint8_t SENSOR_ADDRESS = 0x68;
bool selectMuxChannel(uint8_t channel) {
if (channel > 7) return false;
Wire.beginTransmission(MUX_ADDRESS);
Wire.write(1 << channel);
return Wire.endTransmission() == 0;
}
void setup() {
Serial.begin(9600);
Wire.begin();
}
void loop() {
for (uint8_t channel = 0; channel < 2; channel++) {
if (selectMuxChannel(channel)) {
Wire.beginTransmission(SENSOR_ADDRESS);
bool responds = Wire.endTransmission() == 0;
Serial.print("Channel ");
Serial.print(channel);
Serial.println(responds ? ": sensor found" : ": no response");
}
}
delay(5000);
}The code enables only one channel at a time. Do not enable two channels containing identical addresses unless you intentionally want both targets to respond together.
Electrical considerations
A multiplexer does not automatically solve voltage problems. Check its supply voltage and the pull-up resistors on each side. Some breakout boards include pull-ups on every channel, which can place too many resistors in parallel when channels are enabled.
Exercise
Two sensors both use address 0x68, and each sensor has one address pin that supports 0x69. What should you try before adding a multiplexer?
Show answer
Set the address pin differently on the two sensors, then scan the bus and confirm that one responds at 0x68 and the other at 0x69.