/ examples / vl53l0x_simpletest.py
vl53l0x_simpletest.py
 1  # Simple demo of the VL53L0X distance sensor.
 2  # Will print the sensed range/distance every second.
 3  import time
 4  
 5  import board
 6  import busio
 7  
 8  import adafruit_vl53l0x
 9  
10  # Initialize I2C bus and sensor.
11  i2c = busio.I2C(board.SCL, board.SDA)
12  vl53 = adafruit_vl53l0x.VL53L0X(i2c)
13  
14  # Optionally adjust the measurement timing budget to change speed and accuracy.
15  # See the example here for more details:
16  #   https://github.com/pololu/vl53l0x-arduino/blob/master/examples/Single/Single.ino
17  # For example a higher speed but less accurate timing budget of 20ms:
18  #vl53.measurement_timing_budget = 20000
19  # Or a slower but more accurate timing budget of 200ms:
20  #vl53.measurement_timing_budget = 200000
21  # The default timing budget is 33ms, a good compromise of speed and accuracy.
22  
23  # Main loop will read the range and print it every second.
24  while True:
25      print('Range: {0}mm'.format(vl53.range))
26      time.sleep(1.0)