Skip to content

Commit 35fbd67

Browse files
committed
Add displayio example
1 parent be632f7 commit 35fbd67

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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_scd4x
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+
scd4x = adafruit_scd4x.SCD4X(i2c)
16+
17+
print("Serial number:", [hex(i) for i in scd4x.serial_number])
18+
19+
# Put sensor into working mode, one measurement every 5s
20+
scd4x.start_periodic_measurement()
21+
22+
23+
# Example written for boards with built-in displays
24+
display = board.DISPLAY
25+
26+
# Create a main_group to hold anything we want to show on the display.
27+
main_group = Group()
28+
29+
# Create a Label to show the readings. If you have a very small
30+
# display you may need to change to scale=1.
31+
display_output_label = Label(FONT, text="", scale=2)
32+
33+
# Place the label near the top left corner with anchored positioning
34+
display_output_label.anchor_point = (0, 0)
35+
display_output_label.anchored_position = (4, 4)
36+
37+
# Add the label to the main_group
38+
main_group.append(display_output_label)
39+
40+
# Set the main_group as the root_group of the display
41+
display.root_group = main_group
42+
43+
# Begin main loop
44+
while True:
45+
if scd4x.data_ready:
46+
# Update the label.text property to change the text on the display
47+
# one sensor value per line
48+
display_output_label.text = f"CO2: {scd4x.CO2} ppm \
49+
\nTemperature: {scd4x.temperature:.1f} C \
50+
\nHumidity: {scd4x.relative_humidity:.1f} %"

0 commit comments

Comments
 (0)