Multiple Pimoroni VL53L1X sensors

How can I use multiple sensors of this type on the same raspberry pi? I can’t use Breakout Garden (https://shop.pimoroni.com/products/breakout-garden-hat) because I have to position them in a specific way.
I read about the change-address.py script. Do I have to use that to change address? And how do I connect both of them on the GPIO pins of the raspberry pi?
Thank you

i2c is a shared bus, you can have multiple devices as long as no two devices have the same address. That will happen if you connect two VL53L1X sensors to the one i2c bus that are at the factory settings.
Too get around this most of the Breakout Garden breakouts have a jumper on the back to change its i2c address. You do that to one of them and your good to go.
On that breakout it looks like you run the change-address.py script on “one” of them. Once you do that they will each have a different address and work on the same i2c bus.
Once you have changed the i2c address on one of them you just wire them up in parallel to i2c and power. You’ll have to edit the example and or your py file for two sensors.

What I have done on a couple of my setups is add a Proto Hat and some male headers for my i2c breakouts. Then use female to female jumper wires to connect them to the Proto Hat.

I never used the change-address.py script (https://github.com/pimoroni/vl53l1x-python/blob/master/examples/change-address.py), mine was just an idea. Does this script change the address permanently or does it have to be run at every start?
If it were final, I would have solved it.
Although I don’t know how to connect two sensors at the same time.

I assume its run once to change it. Then run it again if you want to change it back.
If you run i2cdetect -y 1 and take note of its address.
Then run the change-address.py on one sensor, change it, and reboot.
Then run i2c detect -y 1 again. If it has the new address its a only have to run once deal.
To hook up the two sensors you just wire them both to the same GPIO pins.
SDA > SDA >SDA, SCL > SCL> SCL. I would only hookup the INT pin if you have to. And use two different GPIO, a different GPIO for each sensors INT pin.

1 Like

Traceback (most recent call last):
File “_ctypes/callbacks.c”, line 315, in ‘calling callback function’
File “/home/ubuntu/.local/lib/python2.7/site-packages/VL53L1X.py”, line 91, in _i2c_read
self._i2c.i2c_rdwr(msg_w, msg_r)
File “/home/ubuntu/.local/lib/python2.7/site-packages/smbus2/smbus2.py”, line 483, in i2c_rdwr
ioctl(self.fd, I2C_RDWR, ioctl_data)
IOError: [Errno 121] Remote I/O error
Traceback (most recent call last):
File “_ctypes/callbacks.c”, line 315, in ‘calling callback function’
File “/home/ubuntu/.local/lib/python2.7/site-packages/VL53L1X.py”, line 109, in _i2c_write
self._i2c.i2c_rdwr(msg_w)
File “/home/ubuntu/.local/lib/python2.7/site-packages/smbus2/smbus2.py”, line 483, in i2c_rdwr
ioctl(self.fd, I2C_RDWR, ioctl_data)
IOError: [Errno 121] Remote I/O error

This is the error when I run s1.get_distance() after changing address on it

The error is likely because its looking for the sensor at its old address. You have to edit one or two lines in the PY file telling it the new address.
For example in this line
tof = VL53L1X.VL53L1X(i2c_bus=1, i2c_address=0x29)
you have to change the 0x29 to the new address.

Thank you!!! I’ll try!!! :)