Hello,
I've been trying to get multiple VL53L1X to work with a Raspberry pi. I've used the TCA9548A multiplexer but had some issues (see issue #26) and so decided to try using software I2C on the Raspberry Pi as an alternate.
When using the software I2C with multiple sensors, it seems like distance is only read from one sensor and that distance is then displayed as results for all the other sensor running on different I2C busses.
Some testing I did:
- If I use a single I2C bus, I get data from the correct sensor. Tested this on all buses individually (1 through to 6, excluding bus 2). I think this confirms that all the sensors are working and that the software I2C bus has been enabled correctly.
- Ran two sensors together on buses 1 and 3. Distance results for both sensors were being read from sensor on bus 3. *
- Ran the above test again but initialised/opened sensor on bus 3 first and then bus 1. Distance results for both sensors were being read from sensor on bus 1. *
- Ran all five sensors together on buses 1, 3, 4, 5 and 6. Distance results for all sensors were being read from a single sensor on bus 6. *
- Ran the above test again but switched around the sensor initialisation in the following bus order 1, 3, 4, 6, 5. Distance results for all sensors were being read from sensor on bus 5. *
( *Confirmed by physically blocking individual sensors )
So it seems like the sensor on the last initialised/opened bus is always used by the get_distance function (I'm not sure how to explain whats going on here)? Any ideas what might be going on here? Perhaps I've missed something?
Code I used for testing:
import time
import sys
import signal
import VL53L1X
tof1 = VL53L1X.VL53L1X(i2c_bus=1, i2c_address=0x29)
tof2 = VL53L1X.VL53L1X(i2c_bus=3, i2c_address=0x29)
tof3 = VL53L1X.VL53L1X(i2c_bus=4, i2c_address=0x29)
tof4 = VL53L1X.VL53L1X(i2c_bus=5, i2c_address=0x29)
tof5 = VL53L1X.VL53L1X(i2c_bus=6, i2c_address=0x29)
time.sleep(1)
tof1.open()
tof1.start_ranging(3)
tof2.open()
tof2.start_ranging(3)
tof3.open()
tof3.start_ranging(3)
tof4.open()
tof4.start_ranging(3)
tof5.open()
tof5.start_ranging(3)
def exit_handler(signal, frame):
global running
running = False
tof1.stop_ranging()
tof2.stop_ranging()
tof3.stop_ranging()
tof4.stop_ranging()
tof5.stop_ranging()
print()
sys.exit(0)
running = True
signal.signal(signal.SIGINT, exit_handler)
while running:
distance_in_mm = tof1.get_distance()
print("Sensor 1 distance: {}mm".format(distance_in_mm))
distance_in_mm = tof2.get_distance()
print("Sensor 2 distance: {}mm".format(distance_in_mm))
time.sleep(0.5)
distance_in_mm = tof3.get_distance()
print("Sensor 3 distance: {}mm".format(distance_in_mm))
distance_in_mm = tof4.get_distance()
print("Sensor 4 distance: {}mm".format(distance_in_mm))
time.sleep(0.5)
distance_in_mm = tof5.get_distance()
print("Sensor 5 distance: {}mm".format(distance_in_mm))
Hello,
I've been trying to get multiple VL53L1X to work with a Raspberry pi. I've used the TCA9548A multiplexer but had some issues (see issue #26) and so decided to try using software I2C on the Raspberry Pi as an alternate.
When using the software I2C with multiple sensors, it seems like distance is only read from one sensor and that distance is then displayed as results for all the other sensor running on different I2C busses.
Some testing I did:
( *Confirmed by physically blocking individual sensors )
So it seems like the sensor on the last initialised/opened bus is always used by the get_distance function (I'm not sure how to explain whats going on here)? Any ideas what might be going on here? Perhaps I've missed something?
Code I used for testing: