If you run this and it seems to hang, try manually unlocking your I2C bus by running
the following two commands from the REPL.
import board
board.I2C().unlock()
First you create the
creates and saves a
. If the object has already been created, then the existing object is
board.SDA
returned. No matter how many times you call
object. This is called a singleton.
To be able to scan it, you need to lock the I2C down so the only thing accessing it is
the code. So next you include a loop that waits until I2C is locked and then continues
on to the scan function.
Last, you have the loop that runs the actual scan,
refers to addresses in hex form, the example includes 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.
You've connected the MCP9808 which has a 7-bit I2C address of 0x18. The result for
this sensor is
I2C addresses found: ['0x18']
back to the wiring diagrams to make sure you've wired up your sensor correctly.
I2C Sensor Data
Now you know for certain that your sensor is connected and ready to go. Time to find
out how to get the data from the sensor!
Save the following to your CIRCUITPY drive as code.py.
Click the Download Project Bundle button below to download the necessary libraries
and the code.py file in a zip file. Extract the contents of the zip file, find your
CircuitPython version, and copy the matching entire lib folder and code.py file to your
CIRCUITPY drive.
©Adafruit Industries
object, using
i2c
board.I2C()
object using the default pins
busio.I2C
[hex(device_address) for device_address in
. This convenience routine
board.SCL
, it will return the same
board.I2C()
. Because I2C typically
i2c_scan()
. If no addresses are returned, refer
and
Page 161 of 263
Need help?
Do you have a question about the ESP32-S3 and is the answer not in the manual?