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
Содержание Feather M4 Express
Страница 1: ...Adafruit Feather M4 Express Created by lady ada Last updated on 2019 03 04 10 41 14 PM UTC...
Страница 5: ...Adafruit Industries https learn adafruit com adafruit feather m4 express atsamd51 Page 10 of 183...
Страница 58: ...Adafruit Industries https learn adafruit com adafruit feather m4 express atsamd51 Page 63 of 183...
Страница 164: ...Adafruit Industries https learn adafruit com adafruit feather m4 express atsamd51 Page 169 of 183...
Страница 168: ...Adafruit Industries https learn adafruit com adafruit feather m4 express atsamd51 Page 173 of 183...