vl53l1x with raspberry pi pico in cirquit python

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
arucano
 
Posts: 2
Joined: Fri Jan 21, 2022 12:45 am

vl53l1x with raspberry pi pico in cirquit python

Post by arucano »

I have looked at many examples trying to get the VL53L1X with a Pico using the code shown with circuit python examples. I continue to encounter errors win the initial part of the code:
# Simple demo of the VL53L1X distance sensor.
# Will print the sensed range/distance every second.

import time
import board
import adafruit_vl53l1x

i2c = board.I2C()

vl53 = adafruit_vl53l1x.VL53L1X(i2c)

One example referred to the fact that the line "i2c = board.I2C()" would have to be changed for the Pico, but all attempts have failed. If I use busio instead of boards it faults at the next line.
Any help would be highly appreciated

User avatar
tannewt
 
Posts: 3304
Joined: Thu Oct 06, 2016 8:48 pm

Re: vl53l1x with raspberry pi pico in cirquit python

Post by tannewt »

There are instructions on initializing I2C on the Pico here: https://learn.adafruit.com/getting-star ... on/pinouts

If you still have issues, please post the exact code you have and the error message that goes with it.

User avatar
arucano
 
Posts: 2
Joined: Fri Jan 21, 2022 12:45 am

Re: vl53l1x with raspberry pi pico in cirquit python

Post by arucano »

I used the following code, cobbled up from some examples. I am able to detect the address of the VL53L1X but hit a roadblock at line 16. Below are the code and error messages.

CODE:

Code: Select all

import busio
import board
import adafruit_vl53l1x
import time

i2c = busio.I2C(board.GP1, board.GP0)
# added for detection
# Lock the I2C device before we try to scan
while not i2c.try_lock():
    pass
# Print the addresses found once
print("I2C addresses found:", [hex(device_address) for device_address in i2c.scan()])
# Unlock I2C now that we're done scanning.
i2c.unlock()
#
vl53 = adafruit_vl53l1x.VL53L1X(busio.I2C())

while True:
    print("range: mm ", vl53.read())
    time.sleep_ms(50)
ERROR MESSAGE
I2C addresses found: ['0x29']
Traceback (most recent call last):
File "<stdin>", line 16, in <module>
TypeError: 'scl' argument required
Last edited by tannewt on Mon Jan 24, 2022 6:34 pm, edited 1 time in total.
Reason: added code block

User avatar
tannewt
 
Posts: 3304
Joined: Thu Oct 06, 2016 8:48 pm

Re: vl53l1x with raspberry pi pico in cirquit python

Post by tannewt »

Code: Select all

vl53 = adafruit_vl53l1x.VL53L1X(busio.I2C())
should be

Code: Select all

vl53 = adafruit_vl53l1x.VL53L1X(i2c)
The error is due to busio.I2C expecting a scl argument. You already did it correctly before that so you just need to pass in the I2C object you made earlier.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”