Let's add temperature to the multifunction device using the ADT7410 on the Temperature and Motion Wing.
See Multifunction Device Part 1 for a parts list and assembly instructions.
#Import the `adafruit_adt7410` library
#get the I2C device
#instantiate the sensor:
import board
import adafruit_adt7410
i2c = board.I2C()
therm = adafruit_adt7410.ADT7410(i2c)
#functions to read the sensor:
def get_temp_C():
"Temperature Celsius"
T = therm.temperature
return f"{T:0.1f} C"
def get_temp_F():
"Temperature Fahrenheit"
T = therm.temperature * 1.8 + 32
return f"{T:0.1f} F"
We need a Label to display the sensor readings. We'll add it to our 'splash' screen. Then we'll write a function to update the label.
import displayio
from adafruit_bitmap_font.bitmap_font import load_font
from adafruit_display_text.label import Label
METRIC = True
display = board.DISPLAY
splash = displayio.Group()
arial = load_font("/fonts/Arial-18.pcf")
temperature = Label(
arial,
text = "10.0 K",
color = 0x3333FF,
x = display.width * 3 // 8,
y = display.height * 3 // 8)
display.root_group = splash
def loop():
if METRIC:
temperature.text = get_temp_C()
else:
temperataure.text = get_temp_F()
if __name__=="__main__":
while True:
loop()
time.sleep(0.1)
You can find the Arial-18 font here: MagTag Google Calendar. Make a '/fonts' folder on your CIRCUITPY drive and save the font there.
A complete sketch is available on Github: code.py
This page (Desktop Multifunction Device: Time and Temperature) was last updated on February 25, 2024.
Text editor powered by tinymce.