27 lines
680 B
Python
27 lines
680 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()
|
|
|
|
# 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)
|