×

SparkFun will be closed Nov. 28th and Nov. 29th in observance of Thanksgiving. Any orders qualifying for same day shipping placed after 2:00 p.m. MST on Wednesday, Nov 27th will be processed on Monday, Dec 1st. Wishing you a safe and happy holiday weekend from all of us at SparkFun!

All the Ports! And I2C Multiplexing

Want to talk to multiple I2C sensors but have only one address? No problem.

Favorited Favorite 1

We posted the Robotic Finger Sensor two weeks ago. The VCNL4040 only has one set I2C address. What if you want to have a robot with multiple fingers?

Qwiic Mux Shield for Arduino - PCA9548A

SPX-14257
1 Retired

The Qwiic Multiplexer Shield solves it! Easily too. The PCA9548A has 8 to 1 I2C buses. It takes a second to wrap your head around what it's doing but once you get it, it's brilliantly simple.

The PCA9548A is an I2C device that connects to the Arduino. Its default address is 0x70. If you read from this device it will give you one byte: 0b.0000.0000. If you write a 1 into bit 3 (0b.0000.1000) then the mux will connect the Arduino SDA/SCL pins to Port 3.

enableMuxPort(3); //Connect to port 3

Whatever your Arduino code does after that function call the Arduino I2C lines will talk back/forth with whatever is connected on port 3. It's that simple.

Talking to two devices with the same I2C address looks something like this:

enableMuxPort(0);
int myX = getAccelX();
int myY = getAccelY();
int myZ = getAccelZ();
disableMuxPort(0);

enableMuxPort(1);
int myOtherX = getAccelX();
int myOtherY = getAccelY();
int myOtherZ = getAccelZ();
disableMuxPort(1);

It's a neat little part that opens the door to deploy vast arrays of the same sensor. Hope you enjoy!


Comments 0 comments

Related Posts

Recent Posts

Tags


All Tags