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