Simple test

Ensure your device works with this simple test.

examples/pm25_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""
 5Example sketch to connect to PM2.5 sensor with either I2C or UART.
 6"""
 7
 8# pylint: disable=unused-import
 9import time
10import board
11import busio
12from digitalio import DigitalInOut, Direction, Pull
13from adafruit_pm25.i2c import PM25_I2C
14
15
16reset_pin = None
17# If you have a GPIO, its not a bad idea to connect it to the RESET pin
18# reset_pin = DigitalInOut(board.G0)
19# reset_pin.direction = Direction.OUTPUT
20# reset_pin.value = False
21
22
23# For use with a computer running Windows:
24# import serial
25# uart = serial.Serial("COM30", baudrate=9600, timeout=1)
26
27# For use with microcontroller board:
28# (Connect the sensor TX pin to the board/computer RX pin)
29# uart = busio.UART(board.TX, board.RX, baudrate=9600)
30
31# For use with Raspberry Pi/Linux:
32# import serial
33# uart = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=0.25)
34
35# For use with USB-to-serial cable:
36# import serial
37# uart = serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=0.25)
38
39# Connect to a PM2.5 sensor over UART
40# from adafruit_pm25.uart import PM25_UART
41# pm25 = PM25_UART(uart, reset_pin)
42
43# Create library object, use 'slow' 100KHz frequency!
44i2c = busio.I2C(board.SCL, board.SDA, frequency=100000)
45# Connect to a PM2.5 sensor over I2C
46pm25 = PM25_I2C(i2c, reset_pin)
47
48print("Found PM2.5 sensor, reading data...")
49
50while True:
51    time.sleep(1)
52
53    try:
54        aqdata = pm25.read()
55        # print(aqdata)
56    except RuntimeError:
57        print("Unable to read from sensor, retrying...")
58        continue
59
60    print()
61    print("Concentration Units (standard)")
62    print("---------------------------------------")
63    print(
64        "PM 1.0: %d\tPM2.5: %d\tPM10: %d"
65        % (aqdata["pm10 standard"], aqdata["pm25 standard"], aqdata["pm100 standard"])
66    )
67    print("Concentration Units (environmental)")
68    print("---------------------------------------")
69    print(
70        "PM 1.0: %d\tPM2.5: %d\tPM10: %d"
71        % (aqdata["pm10 env"], aqdata["pm25 env"], aqdata["pm100 env"])
72    )
73    print("---------------------------------------")
74    print("Particles > 0.3um / 0.1L air:", aqdata["particles 03um"])
75    print("Particles > 0.5um / 0.1L air:", aqdata["particles 05um"])
76    print("Particles > 1.0um / 0.1L air:", aqdata["particles 10um"])
77    print("Particles > 2.5um / 0.1L air:", aqdata["particles 25um"])
78    print("Particles > 5.0um / 0.1L air:", aqdata["particles 50um"])
79    print("Particles > 10 um / 0.1L air:", aqdata["particles 100um"])
80    print("---------------------------------------")