EasyManuals Logo

Adafruit Feather M4 Express User Manual

Adafruit Feather M4 Express
178 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #152 background imageLoading...
Page #152 background image
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
i2c_unlock() so we can use the sensor for data.
We create our sensor object using the sensor library. We call it tsl2561 and provide it the i2c object.
Then we have a simple loop that prints out the lux reading using the sensor object we created. We add a
time.sleep(1.0) , so it only prints once per second. Connect to the serial console to see the results. Try shining a light
on it to see the results change!
# 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)
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)
© Adafruit Industries https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51 Page 157 of 183

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

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

Adafruit Feather M4 Express Specifications

General IconGeneral
BrandAdafruit
ModelFeather M4 Express
CategoryMicrocontrollers
LanguageEnglish

Related product manuals