2x PiicoDev Laser Distance Sensor VL53L1X using PiicoDev Cable

Hi
I want to connect 2x PiicoDev Laser Distance Sensor VL53L1X using the standard PiicoDev cable. I want to use the standard cables for my students’ ease of use (Software Engineering Mechatronics Project).

Both connect fine using the default address but I can’t separate them. This is the code I have tried, but I get the error below. Rather than use the change_addr method should I jump the IC2 jumpers on the back, but from the docs, I think these are pull-up resistors (although no “PU” printed)?

from PiicoDev_VL53L1X import PiicoDev_VL53L1X
from PiicoDev_Unified import sleep_ms
from time import sleep

# initialise front sensor with default address
distance_front = PiicoDev_VL53L1X()
distance_front.change_addr(0x2B)  # change address to 0x2B
sleep(0.5)  # wait for 0.5 seconds

# initialise right sensor with default address
distance_right = PiicoDev_VL53L1X(0x29)  # initialise sensor B with default address

while True:
    distF = distance_front.read()
    distR = distance_right.read()
    print(
        f"Front Distance: {distF}mm - Right Distance: {distR}mm"
    )  # print both distances on same line
    sleep(0.5)

ERROR:
Traceback (most recent call last):
File “”, line 6, in
File “/lib/PiicoDev_VL53L1X.py”, line 112, in init
File “/lib/PiicoDev_VL53L1X.py”, line 136, in reset
File “/lib/PiicoDev_VL53L1X.py”, line 125, in writeReg
OSError: [Errno 5] EIO

Ben

The VL53L1X has no non-volatile memory, so calling change_addr() only sets the new address while powered on. When it resets, it goes back to 0x29. That means:
You must control which sensor is powered on during address assignment. Here is the video tutorial by Core Electronics.

For distance measurement, you can also use:
https://www.theengineeringprojects.com/2018/10/introduction-to-hc-sr04-ultrasonic-sensor.html

Thanks, @ahsrab292840. Is there a simple way to do this?

My first thought about approaching it is using some while true loops, waiting for a switch signal, and a manual wireup process each time the robot starts, but will that be painful? I like the accuracy and simplicity of these modules, so I’m keen to make it work if possible.

Ben

Hi @Ben89340

Welcome to the forum!

As @ahsrab292840 mentioned you would need to use the SHT pin on the sensors to control which module is powered while it is getting the address assigned.

You could look at a hardware solution, either a multiplexer like this one Adafruit PCA9546 4-Channel STEMMA QT / Qwiic I2C Multiplexer - TCA9546A Compatible | Buy in Australia | ADA5664 | Core Electronics

Or with an I2C address translator like this one Adafruit LTC4316 I2C Address Translator - Stemma QT / Qwiic | Buy in Australia | ADA5914 | Core Electronics

1 Like

@Dan thanks, now the other threads in this forum make more sense.

1 Like