Your CIRCUITPY drive should now look similar to the following image:
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
# SPDX-License-Identifier: MIT
"""CircuitPython I2C MCP9808 Temperature Sensor Example"""
import time
import board
import adafruit_mcp9808
i2c = board.I2C() # uses board.SCL and board.SDA
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a
microcontroller
# import busio
# i2c = busio.I2C(board.SCL1, board.SDA1) # For QT Py RP2040, QT Py ESP32-S2
mcp9808 = adafruit_mcp9808.MCP9808(i2c)
while True:
temperature_celsius = mcp9808.temperature
temperature_fahrenheit = temperature_celsius * 9 / 5 + 32
print("Temperature: {:.2f} C {:.2f} F ".format(temperature_celsius,
temperature_fahrenheit))
time.sleep(2)
The ESP32-S3 TFT Feather STEMMA QT connector is available on board.STEMMA_I2
C() . Comment out the current i2c setup line, and uncomment the the i2c =
board.STEMMA_I2C() line to use with your board's STEMMA QT connector.
This code begins the same way as the scan code, except this time, you create your
sensor object using the sensor library. You call it mcp9808 and provide it the i2c
object.
Then you have a simple loop that prints out the temperature reading using the sensor
object you created. Finally, there's a time.sleep(2) , so it only prints once every two
For the ESP32-S3 TFT Feather, you'll need to change the I2C setup to the
commented out setup included in the code above.
©Adafruit Industries Page 162 of 263