I2C modules make it easy to connect sensors, displays, RTCs, ADCs, DACs and other devices with only two signal wires. But as projects grow, two common problems appear: too many I2C devices with the same address, or not enough digital input/output pins.
An I2C multiplexer and a GPIO expander both help expand a microcontroller project, but they solve different problems. An I2C multiplexer creates separate I2C bus channels. A GPIO expander adds extra digital pins. They are not interchangeable.
The Basic Difference
The easiest way to understand the difference is this:
- I2C multiplexer: adds more I2C bus channels
- GPIO expander: adds more digital input/output pins
If the problem is I2C address conflicts, use a multiplexer. If the problem is not enough digital pins, use a GPIO expander.
I2C Multiplexer: More I2C Bus Channels
An I2C multiplexer, such as the TCA9546 or TCA9548 family, lets one microcontroller talk to several separate I2C branches. The controller selects which channel is active, and then communicates with devices on that selected branch.
- Solves I2C address conflicts
- Allows several identical I2C modules with the same address
- Can separate bus branches physically
- Useful for modular systems
- Does not add general-purpose digital I/O pins
An I2C multiplexer is useful when several devices have the same fixed I2C address or when a project needs separate I2C sections.
GPIO Expander: More Digital Pins
A GPIO expander, such as the MCP23017 or PCF8574, adds digital input and output pins that are controlled over I2C.
- Adds extra digital inputs
- Adds extra digital outputs
- Useful for buttons, switches, LEDs and relay control signals
- Uses only the I2C bus to control many pins
- Does not solve I2C address conflicts between other modules
A GPIO expander is useful when the microcontroller does not have enough digital pins for the project.
Main Comparison Table
| Feature | I2C Multiplexer | GPIO Expander |
|---|---|---|
| Main purpose | Creates multiple selectable I2C bus channels | Adds extra digital input/output pins |
| Solves I2C address conflicts? | Yes | No |
| Adds GPIO pins? | No | Yes |
| Typical chips/modules | TCA9546, TCA9548 and similar I2C multiplexers | MCP23017, PCF8574 and similar GPIO expanders |
| Best for | Multiple identical I2C sensors or displays with the same address | Buttons, LEDs, relay control lines, keypads and digital signals |
| Microcontroller pins used | Uses SDA and SCL | Uses SDA and SCL |
| Software concept | Select channel, then talk to I2C device | Read or write expander registers or pins |
| Main limitation | Only one selected bus path is normally active unless configured otherwise | Pins are slower and less direct than native microcontroller GPIO |
Use an I2C Multiplexer for Address Conflicts
I2C devices need addresses. If two devices with the same fixed address are connected to the same bus, the microcontroller cannot talk to them separately. This is where an I2C multiplexer helps.
The multiplexer places identical devices on different channels. The microcontroller selects one channel at a time, so only the device on that channel responds.
- Two identical sensors with the same fixed address
- Several identical OLED displays
- Multiple identical ADC or DAC modules
- Sensor arrays where each module has the same address
- Projects where address jumpers are not enough
If the same-address devices are on separate multiplexer channels, they can all use the same address without conflict.
Use a GPIO Expander for More Digital Pins
If the project needs more buttons, LEDs, switch inputs or control outputs, an I2C multiplexer will not help. The solution is a GPIO expander.
- More buttons
- More LEDs
- More relay control signals
- More switch inputs
- More keypad lines
- More simple digital control lines
The GPIO expander acts like a remote group of digital pins controlled through I2C.
Example: Two Identical I2C Displays
Suppose a project needs two identical I2C OLED displays, and both displays have the same fixed address. A GPIO expander will not solve this problem because the issue is not a lack of pins. The issue is that both displays respond to the same I2C address.
An I2C multiplexer is the correct solution:
- Display 1 goes on multiplexer channel 0
- Display 2 goes on multiplexer channel 1
- The microcontroller selects channel 0 to update display 1
- The microcontroller selects channel 1 to update display 2
This allows both displays to have the same address while still being controlled separately.
Example: Sixteen Buttons
Suppose a project needs sixteen buttons, but the microcontroller does not have enough free GPIO pins. An I2C multiplexer will not create button inputs. It only switches I2C bus channels.
A GPIO expander is the correct solution:
- Connect buttons to expander input pins
- Use pull-up resistors or internal pull-ups where supported
- Read button states over I2C
- Use an interrupt line if the expander supports it and the project needs it
This adds usable digital inputs without using many microcontroller pins.
Can You Use Both Together?
Yes. In larger projects, an I2C multiplexer and GPIO expanders can be used together.
- A multiplexer can separate several I2C branches
- Each branch can contain sensors, displays or expanders
- GPIO expanders can add local digital I/O on one branch
- This can help organize modular hardware systems
For example, a modular system could use one I2C channel for display modules, another for sensor modules and another for front-panel I/O modules.
Software Difference
The software model is different for the two devices.
With an I2C multiplexer, the software usually selects a channel first, then talks to the target device as if it were on the bus directly.
With a GPIO expander, the software reads and writes the expander pins through registers or library functions.
| Software Task | I2C Multiplexer | GPIO Expander |
|---|---|---|
| Select device path | Yes, select multiplexer channel | No, normally not the purpose |
| Read a button | No, unless a button module exists behind it | Yes |
| Update an I2C display with duplicate address | Yes, select correct channel first | No |
| Turn on an LED connected to the chip | No | Yes, if connected through a suitable resistor/driver |
Speed Considerations
Both devices add some overhead compared with direct connections.
- An I2C multiplexer requires a channel-selection command before talking to devices on that channel
- A GPIO expander requires I2C reads and writes to change or read pins
- Neither is ideal for very fast timing-critical signals
- Native microcontroller pins are better for high-speed interrupts, precise timing or fast pulse generation
For buttons, displays, slow sensors and configuration signals, this is usually not a problem. For fast digital timing, use native pins or dedicated hardware.
Electrical and Bus Considerations
I2C bus wiring still matters when using either type of expansion.
- SDA and SCL need suitable pull-up resistors
- Pull-up voltage must be safe for all connected devices
- Long wires can cause unreliable communication
- Bus capacitance increases as more modules are connected
- Lower I2C speed may improve reliability on longer or larger buses
An I2C multiplexer can sometimes help split bus capacitance between channels, but it should not be used as a substitute for good wiring practices.
Addressing
Both multiplexers and expanders have their own I2C addresses. This means they also occupy addresses on the main bus.
- The multiplexer has an address on the main I2C bus
- The GPIO expander has an address on the I2C bus
- Some modules allow address selection through jumpers or solder pads
- An I2C scanner can help identify devices
- Address conflicts can still happen on the main bus
When planning a larger project, write down all I2C device addresses before assembling the final hardware.
When to Use an I2C Multiplexer
- You have multiple identical I2C modules with the same fixed address
- You need separate I2C branches
- You want to isolate groups of I2C devices
- You need more I2C address space in a modular system
- You want to reduce the number of devices directly connected to one bus segment
An I2C multiplexer is the correct tool when the problem is on the I2C bus itself.
When to Use a GPIO Expander
- You need more digital input pins
- You need more digital output pins
- You need to read buttons or switches
- You need to control LEDs or logic signals
- You want a front-panel I/O module controlled through I2C
A GPIO expander is the correct tool when the problem is not enough digital I/O.
Choosing by Problem Type
| Problem | Correct Solution | Reason |
|---|---|---|
| Two sensors have the same fixed I2C address | I2C multiplexer | Each sensor can be placed on a different bus channel |
| Not enough pins for buttons | GPIO expander | Adds more digital inputs |
| Need to control many LEDs | GPIO expander or LED driver | A multiplexer does not add output pins |
| Several identical OLED displays share one address | I2C multiplexer | Channel selection separates identical addresses |
| Need a 4x4 keypad on I2C | GPIO expander | The keypad needs digital row/column pins |
| One branch of I2C wiring is physically separate | I2C multiplexer may help | Separate channels can organize bus sections |
Common Mistakes
- Buying a GPIO expander to solve duplicate I2C addresses
- Buying an I2C multiplexer to add button inputs
- Assuming a multiplexer makes I2C unlimited
- Ignoring pull-up resistor values and bus capacitance
- Forgetting to select the correct multiplexer channel in software
- Using GPIO expander pins for timing-critical signals
- Trying to drive relays or heavy loads directly from expander pins
When to Use Something Else
Sometimes neither a multiplexer nor a GPIO expander is the best solution.
- Use a larger microcontroller if many fast native pins are required
- Use a shift register if the project only needs many simple outputs
- Use a dedicated LED driver for many LEDs or displays
- Use RS485, CAN or another interface for long-distance wiring
- Use SPI devices when address conflicts are a repeated I2C problem
Conclusion
I2C multiplexers and GPIO expanders both expand a project, but they solve different problems.
- Use an I2C multiplexer when you need more I2C bus channels or need to connect several devices with the same I2C address.
- Use a GPIO expander when you need more digital input or output pins for buttons, LEDs, switches, keypads or control signals.
The key question is simple: is the problem an I2C bus/address problem, or is it a pin-count problem? Once that is clear, the correct module choice becomes much easier.
