Simple test

Ensure your device works with this simple test.

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