Guide for TCA9548A I2C Multiplexer: ESP32, ESP8266, Arduino
Learn how to expand the I2C bus ports (ESP32, ESP8266 NodeMCU, Arduino) using TCA9458A 1-to-8 I2C Multiplexer. It controls multiple I2C devices with the same I2C address.
- Suitable forB.Tech/Diploma IoT/ESP32 students
- Build time1-2 weeks
- LevelBeginner
- Available atAjvika Labs, Kakinada
About this project
In this guide, you’ll learn how to expand the I2C bus ports (ESP32, ESP8266, Arduino) using the TCA9458A 1-to-8 I2C Multiplexer. This piece of hardware is useful if you want to control multiple I2C devices with the same I2C address. For example, multiple OLED displays, or multiple sensors like the BME280.
This tutorial is compatible with ESP32, ESP8266, and Arduino boards. We’ll program the boards using Arduino IDE.
Table of Contents
In this tutorial, we’ll cover the following topics:
Introducing the TCA9548A I2C Multiplexer
TCA9548A Multiplexer Features
TCA9548A Multiplexer I2C address
TCA9548A Pinout
TCA9548A Multiplexer Selecting an I2C Bus
Example 1: Connecting multiple OLED displays
Example 2: Connecting multiple I2C sensors (BME280)
Introducing the TCA9548A 1-to-8 I2C Multiplexer
The I2C communication protocol allows you to communicate with multiple I2C devices on the same I2C bus as long as all devices have a unique I2C address. However, it will not work if you want to connect multiple I2C devices with the same address.
The
TCA9548A I2C multiplexer
allows you to communicate with up to 8 I2C devices with the same I2C bus. The multiplexer communicates with a microcontroller using the I2C communication protocol. Then, you can select which I2C bus on the multiplexer you want to address.
To address a specific port, you just need to send a single byte to the multiplexer with the desired output port number.
TCA9548A Multiplexer Features
Here’s a summary of its main features:
1 to 8 bidireccional translating switches
Active-low reset input
Three address pins—up to 8 TCA9548A devices on the same I2C bus
Channel selection through an I2C bus
Operating power supply voltage range: 1.65V to 5.5V
5V tolerant pins
For a more detailed description, consult the datasheet.
TCA9548A Multiplexer I2C Address
The TCA9548A Multiplexer communicates with a microcontroller using the I2C communication protocol. So, it needs an I2C address. The address of the multiplexer is configurable. You can select a value from 0x70 to 0x77 by adjusting the values of the A0, A1, and A2 pins, as shown in the table below.
A0
A1
A2
I2C Address
LOW
LOW
LOW
0x70
HIGH
LOW
LOW
0x71
LOW
HIGH
LOW
0x72
HIGH
HIGH
LOW
0x73
LOW
LOW
HIGH
0x74
HIGH
LOW
HIGH
0x75
LOW
HIGH
HIGH
0x76
HIGH
HIGH
HIGH
0x77
So, you can connect up to 8 TCA9548A multiplexers to the same I2C bus, which would allow you to connect 64 devices with the same address using only one I2C bus of the microcontroller.
For example, if you connect
A0
A1
, and
A2
to GND, it sets address 0x70 for the multiplexer.
TCA9548A Pinout
The following table describes the TCA9584A Pinout.
Pin
Description
VIN
Powers the multiplexer
GND
Connect to GND
SDA
Connect to the master microcontroller SDA pin
SCL
Connect to the master microcontroller SCL pin
RST
Active low RST pin—can be used to reset the multiplexer
A0
Selects multiplexer I2C address—connect to GND or VCC
A1
Selects multiplexer I2C address—connect to GND or VCC
A2
Selects multiplexer I2C address—connect to GND or VCC
SD0
SDA for channel 0
SC0
SCL for channel 0
SD1
SDA for channel 1
SC1
SCL for channel 1
SD2
SDA for channel 2
SC2
SCL for channel 2
SD3
SDA for channel 3
SC3
SCL for channel 3
SD4
SDA for channel 4
SC4
SCL for channel 4
SD5
SDA for channel 5
SC5
SCL for channel 5
SD6
SDA for channel 6
SC6
SCL for channel 6
SD7
SDA for channel 7
SC7
SCL for channel 7
TCA9548A I2C Multiplexer Selecting an I2C Bus
As mentioned previously, to select a specific I2C bus to read/write data, you just need to send a single byte to the multiplexer with the desired output port number (0 to 7).
To do that, you can simply use the following user-defined function:
void TCA9548A(uint8_t bus){
Wire.beginTransmission(0x70); // TCA9548A address is 0x70
Wire.write(1 << bus); // send byte to select bus
Wire.endTransmission();
Serial.print(bus);
}
Then, you just need to call that function and pass as an argument the port bus number you want to control before sending the I2C commands. For example, to control the device connected to bus number 3, you would call the following line before calling other I2C commands (note that it starts at 0):
TCA9548A(2);
You’ll see how this works with practical examples in the following sections.
Control Multiple OLED Displays—TCA9548A I2C Multiplexer
In this section, we’ll show you how to control multiple OLED displays. As an example, we’ll control four OLED displays, but you can connect up to 8 displays.
Parts Required
Here’s a list of the parts required for this example:
Microcontroller (
ESP32
ESP8266
Arduino
, or other);
TCA9548A I2C Multiplexer
Multiple OLED Displays
(up to 8)
Breadboard
Jumper wires
You can use the preceding links or go directly to
MakerAdvisor.com/tools
to find all the parts for your projects at the best price!
Multiple OLED Displays with I2C Multiplexer Circuit
Connect four OLED displays as shown in the following schematic diagram. We’re using buses number 2, 3, 4 and 5. You can choose any other port number.
We’re also connecting
A0
A1
, and
A2
to GND. This selects address 0x70 for the multiplexer.
Here are the default I2C pins depending on the microcontroller you’re using:
Microcontroller
I2C Pins
ESP32
GPIO 22 (SCL), GPIO 21 (SDA)
ESP8266
GPIO 5 (D1) (SCL), GPIO 4 (D2) (SDA)
Arduino Uno
A5 (SCL), A4 (SDA)
Multiple OLED Displays with I2C Multiplexer Code
Controlling the displays is as easy as controlling one display. You just need to consider selecting the right I2C bus before sending the commands to write to the display.
To learn how to control an I2C display, you can read the following articles:
ESP32 OLED Display with Arduino IDE
ESP8266 0.96 inch OLED Display with Arduino IDE
Guide for I2C OLED Display with Arduino
Installing Libraries
We’ll use the following libraries to control the OLED display. Make sure you have these libraries installed:
Adafruit_SSD1306 library
Adafruit_GFX library
You can install the libraries using the Arduino Library Manager. Go to
Sketch
>
Include Library
>
Manage Libraries
and search for the library name.
If you’re using VS Code with the PlatformIO extension, copy the following to the
platformio.ini
file to include the libraries.
lib_deps = adafruit/Adafruit SSD1306@^2.4.6
adafruit/Adafruit GFX Library@^1.10.10
After installing the libraries, you can proceed.
Copy the following code to your Arduino IDE and upload it to your board. It will work straight away.
/*********
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*********/
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// Select I2C BUS
void TCA9548A(uint8_t bus){
Wire.beginTransmission(0x70); // TCA9548A address
Wire.write(1 << bus); // send byte to select bus
Wire.endTransmission();
Serial.print(bus);
}
void setup() {
Serial.begin(115200);
// Start I2C communication with the Multiplexer
Wire.begin();
// Init OLED display on bus number 2
TCA9548A(2);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
// Clear the buffer
display.clearDisplay();
// Init OLED display on bus number 3
TCA9548A(3);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
// Clear the buffer
display.clearDisplay();
// Init OLED display on bus number 4
TCA9548A(4);
if(!display.begin(SSD1306_SWI
This tutorial is compatible with ESP32, ESP8266, and Arduino boards. We’ll program the boards using Arduino IDE.
Table of Contents
In this tutorial, we’ll cover the following topics:
Introducing the TCA9548A I2C Multiplexer
TCA9548A Multiplexer Features
TCA9548A Multiplexer I2C address
TCA9548A Pinout
TCA9548A Multiplexer Selecting an I2C Bus
Example 1: Connecting multiple OLED displays
Example 2: Connecting multiple I2C sensors (BME280)
Introducing the TCA9548A 1-to-8 I2C Multiplexer
The I2C communication protocol allows you to communicate with multiple I2C devices on the same I2C bus as long as all devices have a unique I2C address. However, it will not work if you want to connect multiple I2C devices with the same address.
The
TCA9548A I2C multiplexer
allows you to communicate with up to 8 I2C devices with the same I2C bus. The multiplexer communicates with a microcontroller using the I2C communication protocol. Then, you can select which I2C bus on the multiplexer you want to address.
To address a specific port, you just need to send a single byte to the multiplexer with the desired output port number.
TCA9548A Multiplexer Features
Here’s a summary of its main features:
1 to 8 bidireccional translating switches
Active-low reset input
Three address pins—up to 8 TCA9548A devices on the same I2C bus
Channel selection through an I2C bus
Operating power supply voltage range: 1.65V to 5.5V
5V tolerant pins
For a more detailed description, consult the datasheet.
TCA9548A Multiplexer I2C Address
The TCA9548A Multiplexer communicates with a microcontroller using the I2C communication protocol. So, it needs an I2C address. The address of the multiplexer is configurable. You can select a value from 0x70 to 0x77 by adjusting the values of the A0, A1, and A2 pins, as shown in the table below.
A0
A1
A2
I2C Address
LOW
LOW
LOW
0x70
HIGH
LOW
LOW
0x71
LOW
HIGH
LOW
0x72
HIGH
HIGH
LOW
0x73
LOW
LOW
HIGH
0x74
HIGH
LOW
HIGH
0x75
LOW
HIGH
HIGH
0x76
HIGH
HIGH
HIGH
0x77
So, you can connect up to 8 TCA9548A multiplexers to the same I2C bus, which would allow you to connect 64 devices with the same address using only one I2C bus of the microcontroller.
For example, if you connect
A0
A1
, and
A2
to GND, it sets address 0x70 for the multiplexer.
TCA9548A Pinout
The following table describes the TCA9584A Pinout.
Pin
Description
VIN
Powers the multiplexer
GND
Connect to GND
SDA
Connect to the master microcontroller SDA pin
SCL
Connect to the master microcontroller SCL pin
RST
Active low RST pin—can be used to reset the multiplexer
A0
Selects multiplexer I2C address—connect to GND or VCC
A1
Selects multiplexer I2C address—connect to GND or VCC
A2
Selects multiplexer I2C address—connect to GND or VCC
SD0
SDA for channel 0
SC0
SCL for channel 0
SD1
SDA for channel 1
SC1
SCL for channel 1
SD2
SDA for channel 2
SC2
SCL for channel 2
SD3
SDA for channel 3
SC3
SCL for channel 3
SD4
SDA for channel 4
SC4
SCL for channel 4
SD5
SDA for channel 5
SC5
SCL for channel 5
SD6
SDA for channel 6
SC6
SCL for channel 6
SD7
SDA for channel 7
SC7
SCL for channel 7
TCA9548A I2C Multiplexer Selecting an I2C Bus
As mentioned previously, to select a specific I2C bus to read/write data, you just need to send a single byte to the multiplexer with the desired output port number (0 to 7).
To do that, you can simply use the following user-defined function:
void TCA9548A(uint8_t bus){
Wire.beginTransmission(0x70); // TCA9548A address is 0x70
Wire.write(1 << bus); // send byte to select bus
Wire.endTransmission();
Serial.print(bus);
}
Then, you just need to call that function and pass as an argument the port bus number you want to control before sending the I2C commands. For example, to control the device connected to bus number 3, you would call the following line before calling other I2C commands (note that it starts at 0):
TCA9548A(2);
You’ll see how this works with practical examples in the following sections.
Control Multiple OLED Displays—TCA9548A I2C Multiplexer
In this section, we’ll show you how to control multiple OLED displays. As an example, we’ll control four OLED displays, but you can connect up to 8 displays.
Parts Required
Here’s a list of the parts required for this example:
Microcontroller (
ESP32
ESP8266
Arduino
, or other);
TCA9548A I2C Multiplexer
Multiple OLED Displays
(up to 8)
Breadboard
Jumper wires
You can use the preceding links or go directly to
MakerAdvisor.com/tools
to find all the parts for your projects at the best price!
Multiple OLED Displays with I2C Multiplexer Circuit
Connect four OLED displays as shown in the following schematic diagram. We’re using buses number 2, 3, 4 and 5. You can choose any other port number.
We’re also connecting
A0
A1
, and
A2
to GND. This selects address 0x70 for the multiplexer.
Here are the default I2C pins depending on the microcontroller you’re using:
Microcontroller
I2C Pins
ESP32
GPIO 22 (SCL), GPIO 21 (SDA)
ESP8266
GPIO 5 (D1) (SCL), GPIO 4 (D2) (SDA)
Arduino Uno
A5 (SCL), A4 (SDA)
Multiple OLED Displays with I2C Multiplexer Code
Controlling the displays is as easy as controlling one display. You just need to consider selecting the right I2C bus before sending the commands to write to the display.
To learn how to control an I2C display, you can read the following articles:
ESP32 OLED Display with Arduino IDE
ESP8266 0.96 inch OLED Display with Arduino IDE
Guide for I2C OLED Display with Arduino
Installing Libraries
We’ll use the following libraries to control the OLED display. Make sure you have these libraries installed:
Adafruit_SSD1306 library
Adafruit_GFX library
You can install the libraries using the Arduino Library Manager. Go to
Sketch
>
Include Library
>
Manage Libraries
and search for the library name.
If you’re using VS Code with the PlatformIO extension, copy the following to the
platformio.ini
file to include the libraries.
lib_deps = adafruit/Adafruit SSD1306@^2.4.6
adafruit/Adafruit GFX Library@^1.10.10
After installing the libraries, you can proceed.
Copy the following code to your Arduino IDE and upload it to your board. It will work straight away.
/*********
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*********/
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// Select I2C BUS
void TCA9548A(uint8_t bus){
Wire.beginTransmission(0x70); // TCA9548A address
Wire.write(1 << bus); // send byte to select bus
Wire.endTransmission();
Serial.print(bus);
}
void setup() {
Serial.begin(115200);
// Start I2C communication with the Multiplexer
Wire.begin();
// Init OLED display on bus number 2
TCA9548A(2);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
// Clear the buffer
display.clearDisplay();
// Init OLED display on bus number 3
TCA9548A(3);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
// Clear the buffer
display.clearDisplay();
// Init OLED display on bus number 4
TCA9548A(4);
if(!display.begin(SSD1306_SWI
Technologies used
Hardware components
- ESP32
- ESP8266
- Arduino
- BME280
- SSD1306
- OLED
Software & tools
- Arduino IDE
- VS Code
- PlatformIO
- PlatformIO
What you get
- Working project / hardware kit, tested before delivery
- Complete source code with explanation
- Project demo and guidance for your viva
- Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed.
Payment is in two parts:
• 50% advance to start the project
• Remaining 50% before delivery
Note:
• Documentation and PPT are not included by default
• If you need documentation/PPT, it can be arranged for extra time and cost
We'll confirm the exact timeline and cost with you after reviewing your requirements.