0

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?

1
  • Why can't you see error messages? Are you using the debugger?
    – Seamus
    Mar 18 at 7:27

2 Answers 2

1

This may be a pull-up resistor issue. Adding devices to an I2C bus will load down the bus, and if it has got to the point where the voltage on the SCL and SDA pins is marginal the interface will behave inconsistently.

If you do not currently have external pullups, you could try any value in the range 2k to 10k. A good starting point might be 4.7k.

1

You have two I2C busses, I2C0 and I2C1.

Connect one VL53 to I2C0 and the other VL53 to I2C1.

Then you can be sure witch VL53 you are communicating with and avoid confusion and changing the address in software.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.