VL53L5CX: MicroPython example.
This commit is contained in:
parent
70637d0f0e
commit
02d3d853f8
|
@ -0,0 +1,32 @@
|
||||||
|
import pimoroni_i2c
|
||||||
|
import breakout_vl53l5cx
|
||||||
|
import time
|
||||||
|
|
||||||
|
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}
|
||||||
|
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21}
|
||||||
|
|
||||||
|
# Sensor startup time is proportional to i2c baudrate
|
||||||
|
# HOWEVER many sensors may not run at > 400KHz (400000)
|
||||||
|
i2c = pimoroni_i2c.PimoroniI2C(**PINS_BREAKOUT_GARDEN, baudrate=2_000_000)
|
||||||
|
|
||||||
|
print("Starting up sensor...")
|
||||||
|
t_sta = time.ticks_ms()
|
||||||
|
sensor = breakout_vl53l5cx.VL53L5CX(i2c)
|
||||||
|
t_end = time.ticks_ms()
|
||||||
|
print("Done in {}ms...".format(t_end - t_sta))
|
||||||
|
|
||||||
|
# Make sure to set resolution and other settings *before* you start ranging
|
||||||
|
sensor.set_resolution(breakout_vl53l5cx.RESOLUTION_4X4)
|
||||||
|
sensor.start_ranging()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
if sensor.data_ready():
|
||||||
|
# "data" is a namedtuple (attrtuple technically)
|
||||||
|
# it includes average readings as "distance_avg" and "reflectance_avg"a
|
||||||
|
# plus a full 4x4 or 8x8 set of readings (as a 1d tuple) for both values.
|
||||||
|
data = sensor.get_data()
|
||||||
|
print("{}mm {}% (avg: {}mm {}%)".format(
|
||||||
|
data.distance[0],
|
||||||
|
data.reflectance[0],
|
||||||
|
data.distance_avg,
|
||||||
|
data.reflectance_avg))
|
Loading…
Reference in New Issue