Adafruit Feather M4 Express Manual page 152

Table of Contents

Advertisement

# CircuitPython Demo - I2C sensor
import time
import adafruit_tsl2561
import board
import busio
i2c = busio.I2C(board.SCL, board.SDA)
# 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)
# 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)
This code begins the same way as the scan code. We've included the scan code so you have verification that your
sensor is wired up correctly and is detected. It prints the address once. After the scan, we unlock I2C with
so we can use the sensor for data.
i2c_unlock()
We create our sensor object using the sensor library. We call it
Then we have a simple loop that prints out the lux reading using the sensor object we created. We add a
, so it only prints once per second. Connect to the serial console to see the results. Try shining a light
time.sleep(1.0)
on it to see the results change!
© Adafruit Industries
for device_address in i2c.scan()])
https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51
and provide it the
tsl2561
object.
i2c
Page 157 of 183

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the Feather M4 Express and is the answer not in the manual?

Related Products for Adafruit Feather M4 Express

Table of Contents

Save PDF