I2C Sensor Data - Adafruit Feather M4 Express Manual

Table of Contents

Advertisement

# CircuitPython demo - I2C scan
import time
import board
import busio
i2c = busio.I2C(board.SCL, board.SDA)
while not i2c.try_lock():
pass
while True:
print("I2C addresses found:", [hex(device_address)
time.sleep(2)
First we create the
object and provide the I2C pins,
i2c
To be able to scan it, we need to lock the I2C down so the only thing accessing it is the code. So next we include a
loop that waits until I2C is locked and then continues on to the scan function.
Last, we have the loop that runs the actual scan,
we've included this bit of code that formats the results into hex format:
.
i2c.scan()]
Open the serial console to see the results! The code prints out an array of addresses. We've connected the TSL2561
which has a 7-bit I2C address of 0x39. The result for this sensor is
returned, refer back to the wiring diagrams to make sure you've wired up your sensor correctly.

I2C Sensor Data

Now we know for certain that our sensor is connected and ready to go. Let's find out how to get the data from our
sensor!
Copy and paste the code into code.py using your favorite editor, and save the file.
© Adafruit Industries
for device_address in i2c.scan()])
i2c_scan()
https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51
and
board.SCL
board.SDA
. Because I2C typically refers to addresses in hex form,
[hex(device_address) for device_address in
I2C addresses found: ['0x39']
.
. If no addresses are
Page 156 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?

Table of Contents

Save PDF