Adafruit_Learning_System_Gu.../CircuitPython_Essentials/CircuitPython_I2C_TSL2591.py
2020-12-16 14:46:09 -05:00

23 lines
579 B
Python

"""CircuitPython Essentials I2C sensor example using TSL2591"""
import time
import board
import adafruit_tsl2591
i2c = board.I2C()
# Lock the I2C device before we try to scan
while not i2c.try_lock():
pass
# Print the addresses found once
print("I2C addresses found:", [hex(device_address) for device_address in i2c.scan()])
# Unlock I2C now that we're done scanning.
i2c.unlock()
# Create library object on our I2C port
tsl2591 = adafruit_tsl2591.TSL2591(i2c)
# Use the object to print the sensor readings
while True:
print("Lux:", tsl2591.lux)
time.sleep(0.5)