17 lines
633 B
Python
17 lines
633 B
Python
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
|
# SPDX-License-Identifier: Unlicense
|
|
"""CircuitPython I2C MCP9808 Temperature Sensor Example"""
|
|
import time
|
|
import board
|
|
import adafruit_mcp9808
|
|
|
|
i2c = board.I2C() # uses board.SCL and board.SDA
|
|
# 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)
|