|
| 1 | +# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries |
| 2 | +# SPDX-FileCopyrightText: 2024 Jose D. Montoya |
| 3 | +# |
| 4 | +# SPDX-License-Identifier: MIT |
| 5 | +import time |
| 6 | +import board |
| 7 | +from adafruit_display_text.bitmap_label import Label |
| 8 | +from terminalio import FONT |
| 9 | +from displayio import Group |
| 10 | +import adafruit_shtc3 |
| 11 | + |
| 12 | + |
| 13 | +# create a main_group to hold anything we want to show on the display. |
| 14 | +main_group = Group() |
| 15 | + |
| 16 | +i2c = board.I2C() # uses board.SCL and board.SDA |
| 17 | +# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller |
| 18 | +sht = adafruit_shtc3.SHTC3(i2c) |
| 19 | + |
| 20 | +# Create a Label to show the readings. If you have a very small |
| 21 | +# display you may need to change to scale=1. |
| 22 | +display_output_label = Label(FONT, text="", scale=1) |
| 23 | + |
| 24 | +# place the label near the top left corner with anchored positioning |
| 25 | +display_output_label.anchor_point = (0, 0) |
| 26 | +display_output_label.anchored_position = (4, 30) |
| 27 | + |
| 28 | +# add the label to the main_group |
| 29 | +main_group.append(display_output_label) |
| 30 | + |
| 31 | +# set the main_group as the root_group of the built-in DISPLAY |
| 32 | +board.DISPLAY.root_group = main_group |
| 33 | + |
| 34 | +# begin main loop |
| 35 | +while True: |
| 36 | + temperature, relative_humidity = sht.measurements |
| 37 | + # Update the label.text property to change the text on the display |
| 38 | + display_output_label.text = ( |
| 39 | + f"Temperature: {temperature:.1f} C Humidity: {relative_humidity:.1f} %" |
| 40 | + ) |
| 41 | + # wait for a bit |
| 42 | + time.sleep(1) |
0 commit comments