Skip to content

Commit a7055f0

Browse files
authoredJan 22, 2025
Merge pull request #22 from jposada202020/main
Adding DisplayIO Simpletest
2 parents 8c8dd8d + 67c2d33 commit a7055f0

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
 

Diff for: ‎docs/examples.rst

+9
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,12 @@ Ensure your device works with this simple test.
66
.. literalinclude:: ../examples/shtc3_simpletest.py
77
:caption: examples/shtc3_simpletest.py
88
:linenos:
9+
10+
DisplayIO Simple test
11+
---------------------
12+
13+
This is a simple test for boards with built-in display.
14+
15+
.. literalinclude:: ../examples/shtc3_displayio_simpletest.py
16+
:caption: examples/shtc3_displayio_simpletest.py
17+
:linenos:

Diff for: ‎examples/shtc3_displayio_simpletest.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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

Comments
 (0)