Muliplexing I2C with the Adafruit TCA9548A multiplexer

I want to attach multiple VL53L0X Time-of-flight sensors to a single I2C bus. It looks as if that should be easy, but it's not.

One solution involves disabling the sensors and then enabling them one at  a time to change their address. It's workable, but fiddly.

If you only have two sensors you could use different I2C buses, but I eventually want to run 8 sensors, so that won't work.

The TCA9548A I2C multiplexer


There is another approach that is easy to implement and works out of the box.

The TCA9548A is an I2C device that acts a little like a telephone exchange.

You can use it to route I2C transactions to one of eight separate I2C busses. That allows you to have eight devices with the same I2C address, one on each bus.

I did a first experiment using an Adafruit CircuitPython m4 feather.

That worked well, and I've just confirmed that it works just as well with a Raspberry Pi. Since I'm using Adafruit's CircuitPython libraries, the same code runs on the Adafruit m4 and the Pi.

As you can see from the image above, the Pi I used was a veteran Pi model 2.

Kudos to the team at Raspberry Pi for maintaining software compatibility, and to Adafruit for making CircuitPython so portable.


Comments

  1. I haven't been able to get the VL53L0X to work with the TCA9548A using Adafruit's Python libraries on the Raspberry Pi. I can't find any example of doing it either.

    The examples of the library adafruit_vl53l0x that I've found instantiate a Python vl53l0x lidar by a call which looks like vl53 = adafruit_vl53l0x.VL53L0X (i2c) where i2c represents the i2c bus. The obvious (to me) way to get the lidar to work with the TCA9548A is to try vl53 = Adafruit)vl53l0x.VL53L0x (tca) where tca is an instantiation of a TCA9548A mux. But that doesn't work. (The corresponding call for a TLV493D magnetic sensor does work.)

    How did you get the lidar to work with the mux?

    Thanks!

    mbob

    ReplyDelete
  2. Apologies for the delay in responding - see my latest post for the explanation.

    From memory, I think I used the Adafruit Blinka library on the Pi. I may have time to check that out in the next few days.

    ReplyDelete

Post a Comment

Popular posts from this blog

Controlling a Raspberry Pi Pico remotely using PySerial

Five steps to connect Jetson Nano and Arduino

Raspberry Pi Pico project 2 - MCP3008