code.py
1 # SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries 2 # 3 # SPDX-License-Identifier: MIT 4 5 """CircuitPython Essentials I2C sensor example using TSL2591""" 6 import time 7 import board 8 import adafruit_tsl2591 9 10 i2c = board.I2C() 11 12 # Lock the I2C device before we try to scan 13 while not i2c.try_lock(): 14 pass 15 # Print the addresses found once 16 print("I2C addresses found:", [hex(device_address) for device_address in i2c.scan()]) 17 18 # Unlock I2C now that we're done scanning. 19 i2c.unlock() 20 21 # Create library object on our I2C port 22 tsl2591 = adafruit_tsl2591.TSL2591(i2c) 23 24 # Use the object to print the sensor readings 25 while True: 26 print("Lux:", tsl2591.lux) 27 time.sleep(0.5)