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