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# You can add an offset to distance measurements here (e.g. calibration)
21# Swapping for the following would add a +10 millimeter offset to measurements:
22# sensor = adafruit_vl6180x.VL6180X(i2c, offset=10)
23
24# Main loop prints the range and lux every second:
25while True:
26    # Read the range in millimeters and print it.
27    range_mm = sensor.range
28    print("Range: {0}mm".format(range_mm))
29    # Read the light, note this requires specifying a gain value:
30    # - adafruit_vl6180x.ALS_GAIN_1 = 1x
31    # - adafruit_vl6180x.ALS_GAIN_1_25 = 1.25x
32    # - adafruit_vl6180x.ALS_GAIN_1_67 = 1.67x
33    # - adafruit_vl6180x.ALS_GAIN_2_5 = 2.5x
34    # - adafruit_vl6180x.ALS_GAIN_5 = 5x
35    # - adafruit_vl6180x.ALS_GAIN_10 = 10x
36    # - adafruit_vl6180x.ALS_GAIN_20 = 20x
37    # - adafruit_vl6180x.ALS_GAIN_40 = 40x
38    light_lux = sensor.read_lux(adafruit_vl6180x.ALS_GAIN_1)
39    print("Light (1x gain): {0}lux".format(light_lux))
40    # Delay for a second.
41    time.sleep(1.0)