Raspberry Pi Pico with PiicoDev VL53L1X failing to connect

Hello!

I’ve been having some issues getting the PiicoDev VL53L1X laser distance sensor to connect to a Pi Pico and was wondering if I could get any input on something I might have overlooked or am obviously getting wrong:

  • The VL53L1X is connected to I2C0 on the Pico, GP20 for SDA and GP21 for SCL, 3.3v for 3.3v and ground for ground.
  • I have the latest PiicoDev python files and no upload/issues with other scripts running on the Pico itself
  • Using the following code, I can see the device at address 0x41 and the device power LED is lit:
from PiicoDev_VL53L1X import PiicoDev_VL53L1X
from time import sleep
from machine import I2C

i2c = machine.I2C(0, scl=21, sda=20, freq=400000)
output = i2c.scan()
print("I2C Scan addresses:")
print(output)

Returns:

I2C Scan addresses:
[41]

But when passing this config into the constructor for the VL53L1X (either with the specified address or just leaving the constructor blank), I receive the following:

from PiicoDev_VL53L1X import PiicoDev_VL53L1X
from time import sleep
from machine import I2C

i2c = machine.I2C(0, scl=21, sda=20, freq=400000)
output = i2c.scan()
print("I2C Scan addresses:")
print(output)
print("Starting Distance Sensor:")
distSensor = PiicoDev_VL53L1X(0, 400000, 20, 21, 0x41)

while True:
    dist = distSensor.read() # read the distance in millimetres
    print(str(dist) + " mm") # convert the number to a string and print
    sleep(0.1)
Starting Distance Sensor:
Traceback (most recent call last):
  File "<stdin>", line 10, in <module>
  File "PiicoDev_VL53L1X.py", line 112, in __init__
  File "PiicoDev_VL53L1X.py", line 136, in reset
  File "PiicoDev_VL53L1X.py", line 125, in writeReg
OSError: [Errno 5] EIO

I’ve checked for any connectivity issues with a basic multimeter and everything seems to be fine, even though the error showing seems to point at that. I’m using a 4pin cable to connect the VL53L1X back to the pico with a cable distance of <76cm but am unsure if this is an issue.

Any ideas on anything I may have missed?
Thanks for any advice in advance!

James.

2 Likes

Hi James,

Welcome to the forum!

From memory the Piicodev initialisation requires the sda and scl objects to be pins instead of ints i.e. Pin(x) not x

1 Like

Thanks for the reply Liam! Yep - I’m a moron. Changing those values to Pin(x) after importing Pin instead of straight ints and I’m now getting data from the sensor successfully. I must’ve missed this - since I switched the numbers between SDA and SCL as part of debugging and it returned a “Invalid SCL pin” error instead, so assumed the int numbers worked. Whoops.

Appreciate the help!

2 Likes

For those playing along at home, the solution was to update the initialisation to be:

from PiicoDev_VL53L1X import PiicoDev_VL53L1X
from time import sleep
from machine import I2C, Pin # Import Pin

i2c = machine.I2C(0, scl=Pin(21), sda=Pin(20), freq=400000) # Use Pin objects to initialise
4 Likes