Skip to content

Commit 6528494

Browse files
authored
Merge pull request #23 from snkYmkrct/main
Add displayio example
2 parents be632f7 + 3a96e59 commit 6528494

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# SPDX-FileCopyrightText: 2024
2+
# SPDX-License-Identifier: MIT
3+
4+
import board
5+
from adafruit_display_text.bitmap_label import Label
6+
from displayio import Group
7+
from terminalio import FONT
8+
9+
import adafruit_scd4x
10+
11+
# Create sensor object, communicating over the board's default I2C bus
12+
i2c = board.I2C() # uses board.SCL and board.SDA
13+
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector
14+
scd4x = adafruit_scd4x.SCD4X(i2c)
15+
16+
print("Serial number:", [hex(i) for i in scd4x.serial_number])
17+
18+
# Put sensor into working mode, one measurement every 5s
19+
scd4x.start_periodic_measurement()
20+
21+
22+
# Example written for boards with built-in displays
23+
display = board.DISPLAY
24+
25+
# Create a main_group to hold anything we want to show on the display.
26+
main_group = Group()
27+
28+
# Create a Label to show the readings. If you have a very small
29+
# display you may need to change to scale=1.
30+
display_output_label = Label(FONT, text="", scale=2)
31+
32+
# Place the label near the top left corner with anchored positioning
33+
display_output_label.anchor_point = (0, 0)
34+
display_output_label.anchored_position = (4, 4)
35+
36+
# Add the label to the main_group
37+
main_group.append(display_output_label)
38+
39+
# Set the main_group as the root_group of the display
40+
display.root_group = main_group
41+
42+
# Begin main loop
43+
while True:
44+
if scd4x.data_ready:
45+
# Update the label.text property to change the text on the display
46+
# one sensor value per line
47+
display_output_label.text = f"CO2: {scd4x.CO2} ppm \
48+
\nTemperature: {scd4x.temperature:.1f} C \
49+
\nHumidity: {scd4x.relative_humidity:.1f} %"

0 commit comments

Comments
 (0)