I²C Addressing & Shared Buses: the short answer
I²C lets many parts share two wires: SDA (data) and SCL (clock), plus power and ground. Each part has an address, such as 0x3C for an SSD1306 OLED or 0x76 for a BME280.
- Level
- Intermediate
- Time
- About 5 min
- Topic
- Communication
Connect several I2C devices to one bus and avoid address clashes.
Before this: Digital Inputs and Outputs
I²C lets many parts share two wires: SDA (data) and SCL (clock), plus power and ground. Each part has an address, such as 0x3C for an SSD1306 OLED or 0x76 for a BME280. The microcontroller calls a part by its address and only that part answers.
Two parts cannot share an address on the same bus. Many modules have a jumper or pin to choose between two addresses.
The lines need pull-up resistors to the supply, usually 4.7 kΩ. Most modules already include them. Several modules in parallel lower the total resistance; that is usually fine for two or three, but check if you add many.
Keep wires short (under 30 cm on a breadboard). Default pins: Uno A4 (SDA) and A5 (SCL); ESP32 GPIO21 (SDA) and GPIO22 (SCL).
How a transaction works
The controller starts by pulling SDA low while SCL is high (a start condition), sends the 7-bit address and a read/write bit, and the addressed device pulls SDA low for one clock to say it is there (an acknowledgement). Data then follows in bytes, each acknowledged. A stop condition ends it. If no device answers, the controller sees a missing acknowledgement and the library reports an error.
The lines are open-drain: devices only pull them low, and the pull-up resistors raise them. That is why the pull-ups matter, and why two devices can never fight over a line.
Pull-up values and bus speed
The rise time of the lines depends on the pull-up resistance and the bus capacitance (wires and device pins). For a 100 kHz bus, 4.7 kΩ works for short wiring. At 400 kHz, with more capacitance, use 2.2 kΩ to 3.3 kΩ. A resistor that is too small makes the devices work too hard to pull the line down; too large makes the edges slow and the data unreliable.
Several breakout modules each carry their own pull-ups, in parallel. Three modules with 4.7 kΩ pull-ups give about 1.6 kΩ in total, which is near the limit of what many devices can sink. If a bus misbehaves after adding a module, remove or desolder some pull-ups.
Solving address clashes
Check the address with a scanner sketch. Many parts have an address-select pin or jumper that gives two or four choices, for example an MPU6050 at 0x68 or 0x69. When two parts have fixed identical addresses, use an I²C multiplexer such as the TCA9548A, which gives each device its own channel, or put them on a second I²C bus; an ESP32 has two.
Remember that the address in datasheets is sometimes written as 8 bits. The Arduino Wire library uses 7 bits, so a datasheet value of 0x78 for an OLED becomes 0x3C.
Voltage levels and troubleshooting
Mixing 3.3 V and 5 V devices on one bus needs a level shifter designed for open-drain lines, because a simple one-way shifter cannot work in both directions. When a device stops answering, check the power, then the wiring, then the address, and with a scope or logic analyser look at whether the lines reach full height and drop low enough. A device holding SDA low can lock up the bus; a power cycle clears it, and many libraries can toggle the clock to free it.
- Adding pull-ups on top of the ones already on the modules.
- Using the 8-bit address from a datasheet in a 7-bit library.
- Running long jumper wires at 400 kHz.
- tr ≈ 0.85 × Rp × Cb
- 30 % to 70 % rise time
- Rp(min) = (Vdd − 0.4) ÷ 3 mA
- smallest pull-up for standard I²C
A line rising after release
Work it with your own numbers: I²C address check
Practise this lesson with Maker
The explanation above is free for everyone. The practice for Intermediate lessons in every domain are part of the Maker plan at ₹499 a month, and Pro includes them too.
With Maker you also get: a worked example, a hands-on task, a 3-question check.
