Daisy chaining ToF sensors
A work-around for implementing an array of time-of-flight sensors on a single I2C bus using daisy chained addressing. This was used in the GR8BOT project
Introduction
Time of flight (ToF) sensors are widely used for many applications as a low-cost means to measure proximity. The vast majority of models use a fixed I2C address that can be reprogrammed after pulling the enable signal high. Frustratingly, this means that in order to have an array of sensors on the same I2C bus you need to have a GPIO for each to be able to set the addresses individually. This approach needlessly uses up IO pins on the microcontroller, defeating the purpose of I2C being a 2-wire protocol in the first place. One solution would be to use an I2C IO expander - this still leaves us with a rats nest of wires, for no purpose other than to configure the address on initilisation.
Daisy chaining sensors
Some ToF sensors, including the TMF8806 I ended up using, feature a programmable GPIO pin. By configuring the gpio of one sensor to trigger the enabling signal of the next, the sensors can be daisy chained to each with no increase in the number of pins required. I added a buffer on the output of the GPIO, both to ensure that the current is suffient to drive the signal and prevent an undefined state on start up.
Implementing the init sequence
To implement the daisy chained addressing, all sensors are initially disabled, then the first sensor is enabled, and set to a new address over I2C. Once it’s taken on it’s new address, it’s gpio pin is set to high - triggering the enable signal for the next sensor. After all sensors have been configured to their new addresses, they remain on and are polled as normal until the next power cycle.
Routing The Bus
The PCBs were designed in a way that makes them easy to physically daisy chain, with a input molex connector for the power, I2C and enable lines on one side and a corresponding output connector, with the sensor branching off this. A pair of LEDs were added to help with troubleshooting and ideally a lens case would have been made but I never got round to that. They ultimately do the job they were designed for and can be scaled to how ever many devices your I2C bus can handle.