code.py
1 # SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries 2 # 3 # SPDX-License-Identifier: MIT 4 5 """ 6 CircuitPython U2IF I2C QT2040 Trinkey Example 7 8 Reads the temperature every two seconds from an MCP9808 I2C temperature sensor 9 connected via STEMMA QT. 10 """ 11 import time 12 import board 13 import adafruit_mcp9808 14 15 i2c = board.I2C() # uses board.SCL and board.SDA 16 mcp9808 = adafruit_mcp9808.MCP9808(i2c) 17 18 while True: 19 temperature_celsius = mcp9808.temperature 20 temperature_fahrenheit = temperature_celsius * 9 / 5 + 32 21 print("Temperature: {:.2f} C {:.2f} F ".format(temperature_celsius, temperature_fahrenheit)) 22 time.sleep(2)