Blog · Tutorial

TCA9548A i2c multiplexer tutorial: 8 sensors, one address

Tutorial

Eight identical sensors, every one insisting on the same address — the TCA9548A makes the problem disappear for a few dollars. One select byte, then everything behaves like a normal bus.

The idea

How the TCA9548A works: a railway switch for your bus

The TCA9548A sits on your i2c bus at 0x70 (selectable up to 0x77 via the A0–A2 pins) and fans out to eight isolated downstream channels. Whatever channel you open gets electrically connected to the host bus; the other seven don't exist as far as the controller is concerned. Eight BME280s can all keep their default 0x76 — they just live on different channels, and since each channel is isolated, the chip also resets the accumulated pull-up and capacitance load of a big chain. It's the heavy-duty answer from our address-conflict guide, in practice.

Wiring is unremarkable: VCC, GND, SDA, SCL on the host side; each channel exposes its own SDn/SCn pair. One select byte does everything — bit N opens channel N.

Arduino

TCA9548A Arduino code: the four lines that matter

#include <Wire.h>
#define MUX_ADDR 0x70

void muxSelect(uint8_t channel) {       // 0-7
  Wire.beginTransmission(MUX_ADDR);
  Wire.write(1 << channel);             // bitmask: one bit per channel
  Wire.endTransmission();
}

That's the entire driver. Reading four same-address sensors becomes:

for (uint8_t ch = 0; ch < 4; ch++) {
  muxSelect(ch);
  float t = readSensorAt0x76();   // your normal sensor code, unchanged
  Serial.printf("sensor %u: %.2f\n", ch, t);
}

The select is sticky — it persists until the next write — so libraries that know nothing about multiplexers work untouched: select the channel, then call the library exactly as in our Arduino Wire tutorial. One habit worth keeping: initialise each sensor's library object after selecting its channel the first time.

MicroPython

TCA9548A in MicroPython: same trick, Python flavour

from machine import I2C, Pin
i2c = I2C(0, sda=Pin(0), scl=Pin(1))

def mux_select(ch):
    i2c.writeto(0x70, bytes([1 << ch]))

for ch in range(4):
    mux_select(ch)
    print(ch, i2c.scan())   # each scan sees only that channel (plus 0x70)

That scan loop is also the best debugging tool the part has: channel by channel, you see exactly which devices are alive where. (Full MicroPython bus basics in the MicroPython i2c tutorial.)

Gotchas

Three TCA9548A gotchas that bite

The mux answers scans too. 0x70 always appears in a bus scan alongside the selected channel's devices. Don't mistake it for a sensor — and keep 0x70–0x77 free of other parts unless you've moved the mux's address.

Selection is per-controller-reset, not per-transaction. After a reboot the mux comes up with all channels closed — if your code "worked yesterday," check that setup selects a channel before the first sensor call.

Open channels sum their loads. Opening several channels at once reconnects all their pull-ups and wiring capacitance to one bus — long chains can sag back into rise-time trouble. One channel at a time is the reliable default.

Questions

TCA9548A FAQ

How does the TCA9548A select a channel?

You write one byte to the mux's own address (0x70 by default): a bitmask where bit N opens channel N. 0x01 opens channel 0, 0x08 opens channel 3, 0x00 closes everything. The setting persists until you write a new mask, so you select once, then talk to the downstream device completely normally.

Can I open two multiplexer channels at the same time?

Yes — the byte is a bitmask, so 0x03 opens channels 0 and 1 together. That's useful for broadcasting to several identical devices at once, but if two open channels hold same-address devices, reads will collide exactly like they would on a bare bus. For one-at-a-time sensors, write a single-bit mask each time.

Does the TCA9548A work with different voltages on each side?

Yes — its pass-gate design translates levels: run the host side at your controller's voltage and pull each downstream channel up to its own device's voltage (1.8–5 V). That makes it a level shifter and a conflict-solver in one part.

What if I need more than 8 devices?

The mux's own address is selectable via A0–A2 (0x70–0x77), so eight multiplexers fit one bus — 64 channels. Just keep 0x70–0x77 clear of other parts, and remember each open channel adds its devices' bus capacitance and pull-ups to the live bus.

TCA9548A or PCA9548A — does it matter?

They're functionally interchangeable 8-channel i2c switches with the same register interface; the TCA is TI's newer part with wider supply range. Code written for one drives the other unmodified.