Simple test

Ensure your device works with this simple test.

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