Due to the impacts of the coronavirus outbreak, we are experiencing longer than normal lead times on certain products. We encourage back-ordering out-of-stock items to receive them as soon as possible.
Want to talk to multiple I2C sensors but have only one address? No problem.
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?
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!