Simple test¶
Ensure your device works with this simple test.
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4import time
5import board
6import busio
7import adafruit_lidarlite
8
9
10# Create library object using our Bus I2C port
11i2c = busio.I2C(board.SCL, board.SDA)
12
13# Default configuration, with only i2c wires
14sensor = adafruit_lidarlite.LIDARLite(i2c)
15
16# Optionally, we can pass in a hardware reset pin, or custom config
17# import digitalio
18# reset = digitalio.DigitalInOut(board.D5)
19# sensor = adafruit_lidarlite.LIDARLite(i2c, reset_pin=reset,
20# configuration=adafruit_lidarlite.CONFIG_MAXRANGE)
21
22# If you want to reset, you can do so, note that it can take 10-20 seconds
23# for the data to 'normalize' after a reset (and this isnt documented at all)
24# sensor.reset()
25
26while True:
27 try:
28 # We print tuples so you can plot with Mu Plotter
29 print((sensor.distance,))
30 except RuntimeError as e:
31 # If we get a reading error, just print it and keep truckin'
32 print(e)
33 time.sleep(0.01) # you can remove this for ultra-fast measurements!