PM2.5 模块
PM2.5 空气质量模块是一款环境空气质量检测模块。该产品采用 PMSA003 数字通用颗粒物浓度传感器,可快速采集并计算单位体积空气中不同粒径悬浮颗粒的数量。
另外两个版本配备 STH30 和 SHT20,可用于测量环境温度和湿度。
支持以下产品:
MicroPython 应用示例:
1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8from module import PM25Module 9import time 10 11 12title0 = None 13label9 = None 14label0 = None 15label10 = None 16label1 = None 17label2 = None 18label3 = None 19label4 = None 20label5 = None 21label6 = None 22label7 = None 23label8 = None 24pm25_0 = None 25 26 27def setup(): 28 global \ 29 title0, \ 30 label9, \ 31 label0, \ 32 label10, \ 33 label1, \ 34 label2, \ 35 label3, \ 36 label4, \ 37 label5, \ 38 label6, \ 39 label7, \ 40 label8, \ 41 pm25_0 42 43 M5.begin() 44 Widgets.fillScreen(0x222222) 45 title0 = Widgets.Title("PM2.5 Module Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) 46 label9 = Widgets.Label("Temp:", 191, 26, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 47 label0 = Widgets.Label("PM1.0 Env:", 1, 26, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 48 label10 = Widgets.Label("Humi:", 191, 52, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 49 label1 = Widgets.Label("PM2.5 Env:", 1, 52, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 50 label2 = Widgets.Label("PM10 Env:", 1, 77, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 51 label3 = Widgets.Label( 52 "Particles 0.3um:", 1, 100, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 53 ) 54 label4 = Widgets.Label( 55 "Particles 0.5um:", 1, 124, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 56 ) 57 label5 = Widgets.Label( 58 "Particles 1.0um:", 1, 145, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 59 ) 60 label6 = Widgets.Label( 61 "Particles 2.5um:", 1, 167, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 62 ) 63 label7 = Widgets.Label( 64 "Particles 5um:", 1, 189, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 65 ) 66 label8 = Widgets.Label( 67 "Particles 10um:", 1, 210, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 68 ) 69 70 pm25_0 = PM25Module(2) 71 pm25_0.set_module_mode(0) 72 pm25_0.set_module_power(True) 73 print(pm25_0.get_module_power()) 74 75 76def loop(): 77 global \ 78 title0, \ 79 label9, \ 80 label0, \ 81 label10, \ 82 label1, \ 83 label2, \ 84 label3, \ 85 label4, \ 86 label5, \ 87 label6, \ 88 label7, \ 89 label8, \ 90 pm25_0 91 M5.update() 92 pm25_0.request_air_data() 93 pm25_0.refresh_data() 94 label0.setText(str((str("PM1.0 Env:") + str((pm25_0.get_pm_data(3)))))) 95 label1.setText(str((str("PM2.5 Env:") + str((pm25_0.get_pm_data(4)))))) 96 label2.setText(str((str("PM10 Env:") + str((pm25_0.get_pm_data(5)))))) 97 label3.setText(str((str("Particles 0.3um:") + str((pm25_0.get_pm_data(6)))))) 98 label4.setText(str((str("Particles 0.5um:") + str((pm25_0.get_pm_data(7)))))) 99 label5.setText(str((str("Particles 1.0um:") + str((pm25_0.get_pm_data(8)))))) 100 label6.setText(str((str("Particles 2.5um:") + str((pm25_0.get_pm_data(9)))))) 101 label7.setText(str((str("Particles 5um:") + str((pm25_0.get_pm_data(10)))))) 102 label8.setText(str((str("Particles 10um:") + str((pm25_0.get_pm_data(11)))))) 103 label9.setText(str((str("Temp:") + str((pm25_0.get_temperature()))))) 104 label10.setText(str((str("Humi:") + str((pm25_0.get_humidity()))))) 105 time.sleep_ms(100) 106 107 108if __name__ == "__main__": 109 try: 110 setup() 111 while True: 112 loop() 113 except (Exception, KeyboardInterrupt) as e: 114 try: 115 from utility import print_error_msg 116 117 print_error_msg(e) 118 except ImportError: 119 print("please update to latest firmware")
UiFlow2 应用示例:
class PM25Module
Constructors
- class PM25Module
使用 UART 初始化 PM2.5 模块。
UIFLOW2:

Methods
- PM25Module.set_module_power(state)
设置 PM25Module 的电源状态。
- 参数:
state – 设置为 True 以启用电源,设置为 False 以禁用。
UIFLOW2:

- PM25Module.set_module_mode(mode)
设置 PM25Module 的工作模式。
- 参数:
mode – 选项:-
Active mode:1 -Passive mode:0
UIFLOW2:

- PM25Module.refresh_data()
刷新 PM25Module 数据。
- 参数:
mode – 选项:-
Active mode:1 -Passive mode:0
UIFLOW2:

- PM25Module.request_air_data()
请求 PM25Module 空气数据。
UIFLOW2:

- PM25Module.get_pm_data(data_num)
选择要获取的颗粒物数据类型。
- 参数:
data_num (int) – 选项范围从标准 PM 浓度到 0.1 升空气中特定粒径的颗粒计数。选项:-
PM1.0 Concentration(Std):0 -PM2.5 Concentration(Std):1 -PM10 Concentration(Std):2 -PM1.0 Concentration(Env):3 -PM2.5 Concentration(Env):4 -PM10 Concentration(Env):5 -Particels more than 0.3um in 0.1 liters of air:6 -Particels more than 0.5um in 0.1 liters of air:7 -Particels more than 1.0um in 0.1 liters of air:8 -Particels more than 2.5um in 0.1 liters of air:9 -Particels more than 5.0um in 0.1 liters of air:10 -Particels more than 10um in 0.1 liters of air:11
UIFLOW2:

- PM25Module.get_temperature()
获取 PM25Module 环境温度数据。
UIFLOW2:

- PM25Module.get_humidity()
获取 PM25Module 环境湿度数据。
UIFLOW2:

/img-3fdafe0e-bb11-4ad5-b6d6-061919cc735b.webp)

/img-1e1a8f8e-bea0-4cd1-a82d-274c22ad7e79.webp)

