Skip to content

Commit 380641e

Browse files
authored
Merge pull request #15 from snkYmkrct/main
Add displayio example
2 parents a727b08 + dda9e40 commit 380641e

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# SPDX-FileCopyrightText: 2024
2+
# SPDX-License-Identifier: MIT
3+
4+
import time
5+
import board
6+
from adafruit_display_text.bitmap_label import Label
7+
from displayio import Group
8+
from terminalio import FONT
9+
10+
import adafruit_sht4x
11+
12+
# Create sensor object, communicating over the board's default I2C bus
13+
i2c = board.I2C() # uses board.SCL and board.SDA
14+
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector
15+
sht = adafruit_sht4x.SHT4x(i2c)
16+
17+
print("Found SHT4x with serial number", hex(sht.serial_number))
18+
19+
sht.mode = adafruit_sht4x.Mode.NOHEAT_HIGHPRECISION
20+
# Can also set the mode to enable heater
21+
# sht.mode = adafruit_sht4x.Mode.LOWHEAT_100MS
22+
# print("Current mode is: ", adafruit_sht4x.Mode.string[sht.mode])
23+
24+
25+
# Example written for boards with built-in displays
26+
display = board.DISPLAY
27+
28+
# Create a main_group to hold anything we want to show on the display.
29+
main_group = Group()
30+
31+
# Create a Label to show the readings. If you have a very small
32+
# display you may need to change to scale=1.
33+
display_output_label = Label(FONT, text="", scale=2)
34+
35+
# Place the label near the top left corner with anchored positioning
36+
display_output_label.anchor_point = (0, 0)
37+
display_output_label.anchored_position = (4, 4)
38+
39+
# Add the label to the main_group
40+
main_group.append(display_output_label)
41+
42+
# Set the main_group as the root_group of the display
43+
display.root_group = main_group
44+
45+
# Begin main loop
46+
while True:
47+
temperature, relative_humidity = sht.measurements
48+
# Update the label.text property to change the text on the display
49+
display_output_label.text = (
50+
f"Temperature: {temperature:.1f} C \nHumidity: {relative_humidity:.1f} %"
51+
)
52+
# Wait for a bit
53+
time.sleep(1)

0 commit comments

Comments
 (0)