The MCP9808 is an awesome, high accuracy temperature sensor that communicates over I2C. Its available on Adafruit as a breakout.
This driver depends on the Bus Device library. Please ensure it is also available on the CircuitPython filesystem. This is easily achieved by downloading a library and driver bundle.
Getting the temperature in Celsius is easy! First, import all of the pins from the board, busio for native I2C communication and the thermometer library itself.
from board import *
import busio
import adafruit_mcp9808
Next, initialize the I2C bus in a with statement so it always gets shut down ok. Then, construct the thermometer class:
# Do one reading
with busio.I2C(SCL, SDA) as i2c:
t = adafruit_mcp9808.MCP9808(i2c)
# Finally, read the temperature property and print it out
print(t.temperature)
api