Simple test

Ensure your device works with this simple test.

examples/tsl2561_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4import time
 5import board
 6import busio
 7import adafruit_tsl2561
 8
 9# Create the I2C bus
10i2c = busio.I2C(board.SCL, board.SDA)
11
12# Create the TSL2561 instance, passing in the I2C bus
13tsl = adafruit_tsl2561.TSL2561(i2c)
14
15# Print chip info
16print("Chip ID = {}".format(tsl.chip_id))
17print("Enabled = {}".format(tsl.enabled))
18print("Gain = {}".format(tsl.gain))
19print("Integration time = {}".format(tsl.integration_time))
20
21print("Configuring TSL2561...")
22
23# Enable the light sensor
24tsl.enabled = True
25time.sleep(1)
26
27# Set gain 0=1x, 1=16x
28tsl.gain = 0
29
30# Set integration time (0=13.7ms, 1=101ms, 2=402ms, or 3=manual)
31tsl.integration_time = 1
32
33print("Getting readings...")
34
35# Get raw (luminosity) readings individually
36broadband = tsl.broadband
37infrared = tsl.infrared
38
39# Get raw (luminosity) readings using tuple unpacking
40# broadband, infrared = tsl.luminosity
41
42# Get computed lux value (tsl.lux can return None or a float)
43lux = tsl.lux
44
45# Print results
46print("Enabled = {}".format(tsl.enabled))
47print("Gain = {}".format(tsl.gain))
48print("Integration time = {}".format(tsl.integration_time))
49print("Broadband = {}".format(broadband))
50print("Infrared = {}".format(infrared))
51if lux is not None:
52    print("Lux = {}".format(lux))
53else:
54    print("Lux value is None. Possible sensor underrange or overrange.")
55
56# Disble the light sensor (to save power)
57tsl.enabled = False