/ examples / vl6180x_simpletest.py
vl6180x_simpletest.py
 1  # Demo of reading the range and lux from the VL6180x distance sensor and
 2  # printing it every second.
 3  # Author: Tony DiCola
 4  import time
 5  
 6  import board
 7  import busio
 8  
 9  import adafruit_vl6180x
10  
11  
12  # Create I2C bus.
13  i2c = busio.I2C(board.SCL, board.SDA)
14  
15  # Create sensor instance.
16  sensor = adafruit_vl6180x.VL6180X(i2c)
17  
18  # Main loop prints the range and lux every second:
19  while True:
20      # Read the range in millimeters and print it.
21      range_mm = sensor.range
22      print("Range: {0}mm".format(range_mm))
23      # Read the light, note this requires specifying a gain value:
24      # - adafruit_vl6180x.ALS_GAIN_1 = 1x
25      # - adafruit_vl6180x.ALS_GAIN_1_25 = 1.25x
26      # - adafruit_vl6180x.ALS_GAIN_1_67 = 1.67x
27      # - adafruit_vl6180x.ALS_GAIN_2_5 = 2.5x
28      # - adafruit_vl6180x.ALS_GAIN_5 = 5x
29      # - adafruit_vl6180x.ALS_GAIN_10 = 10x
30      # - adafruit_vl6180x.ALS_GAIN_20 = 20x
31      # - adafruit_vl6180x.ALS_GAIN_40 = 40x
32      light_lux = sensor.read_lux(adafruit_vl6180x.ALS_GAIN_1)
33      print("Light (1x gain): {0}lux".format(light_lux))
34      # Delay for a second.
35      time.sleep(1.0)