I am using to VL53 lidar sensor chips on a single I2C bus.
This specific chip does not have an option to change I2C address through hardware and so I must do it through software. This works and I am able to see the two chips with different addresses.
I then am able to make multiple calls to the ping method, and get valid distances back from both sensors. This works once or twice but then I2C seems to "forget" about the sensors and eventually they completely time out and return no data.
This is really hard to debug because I can't see the error messages.
from https://github.com/orionrobots/vl53l0x/blob/main/two_tof_single_bus.py:
from machine import Pin, I2C
from vl53l0x import setup_tofl_device, TBOOT
import utime
device_1_xshut = Pin(16, Pin.OUT)
i2c_1 = I2C(id=1, sda=Pin(14), scl=Pin(15))
# Set this low to disable device 1
print("Setting up device 0")
device_1_xshut.value(0)
tofl0 = setup_tofl_device(i2c_1, 40000, 12, 8)
tofl0.set_address(0x31)
try:
print("Now setting up device 1")
# Re-enable device 1 - on the same bus
device_1_xshut.value(1)
utime.sleep_us(TBOOT)
tofl1 = setup_tofl_device(i2c_1, 40000, 12, 8)
while True:
left, right = tofl0.ping(), tofl1.ping()
print(left, 'mm, ', right, 'mm')
# left = tofl0.ping()
# print(left, 'mm')
finally:
# Restore default address
print("Restoring")
tofl0.set_address(0x29)
This code does work, but after a while the behaviour mentioned above returns.
Can anyone suggest what may be going wrong?