Adafruit_Learning_System_Gu.../CircuitPython_Essentials/CircuitPython_I2C_TSL2561.py

26 lines
582 B
Python

# CircuitPython Demo - I2C sensor
import time
import adafruit_tsl2561
import board
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
tsl2561 = adafruit_tsl2561.TSL2561(i2c)
# Use the object to print the sensor readings
while True:
print("Lux:", tsl2561.lux)
time.sleep(1.0)