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
+ from adafruit_pm25 .i2c import PM25_I2C
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
+ pm25 = PM25_I2C (i2c , reset_pin = None )
16
+
17
+
18
+ # Example written for boards with built-in displays
19
+ display = board .DISPLAY
20
+
21
+ # Create a main_group to hold anything we want to show on the display.
22
+ main_group = Group ()
23
+
24
+ # Create a Label to show the readings. If you have a very small
25
+ # display you may need to change to scale=1.
26
+ display_output_label = Label (FONT , text = "" , scale = 2 )
27
+
28
+ # Place the label near the top left corner with anchored positioning
29
+ display_output_label .anchor_point = (0 , 0 )
30
+ display_output_label .anchored_position = (4 , 4 )
31
+
32
+ # Add the label to the main_group
33
+ main_group .append (display_output_label )
34
+
35
+ # Set the main_group as the root_group of the display
36
+ display .root_group = main_group
37
+
38
+ # Begin main loop
39
+ while True :
40
+ try :
41
+ aqdata = pm25 .read ()
42
+ except RuntimeError :
43
+ continue
44
+ # Update the label.text property to change the text on the display
45
+ # show some of the values returned by the sensor read, one per line
46
+ display_output_label .text = f"PM 1.0: { aqdata ["pm10 standard" ]} \
47
+ \n PM 2.5: { aqdata ["pm25 standard" ]} \
48
+ \n 1.0um / 0.1L: { aqdata ["particles 10um" ]} \
49
+ \n 2.5um / 0.1L: { aqdata ["particles 25um" ]} "
50
+ # Wait a bit between reads
51
+ time .sleep (1 )
0 commit comments