Adafruit_Learning_System_Gu.../CircuitPython_Essentials/CircuitPython_I2C_TSL2591/code.py
2022-12-21 15:37:40 -05:00

28 lines
806 B
Python

# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""CircuitPython Essentials I2C sensor example using TSL2591"""
import time
import board
import adafruit_tsl2591
i2c = board.I2C() # uses board.SCL and board.SDA
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
# 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)