The SDS011
Class:
- class src.utils.sds011.SDS011(serial_port: str, baudrate: int = 9600, timeout: int = 2, use_query_mode: bool = True)[source]
Provides functionality to read from a SDS011 air particlate density sensor using UART serial communication.
- __init__(serial_port: str, baudrate: int = 9600, timeout: int = 2, use_query_mode: bool = True)[source]
Initialise and open serial port.
- Parameters:
serial_port (str) – The serial port (device path) on which the sensor is mounted. Ex: “/dev/ttyUSB0”
baudrate (int) – The rate at which information is transferred in a communication channel. See baudrate.
timeout (int) – The number of seconds to wait for a response from the sensor.
use_query_mode (bool) – Whether to use the sensor’s query mode. This should always be set to true for out applications.
- __weakref__
list of weak references to the object
- _execute(cmd_bytes: bytes)[source]
Writes a byte sequence to the serial port (device).
- Parameters:
cmd_bytes (bytes) – The bytes that should be sent.
- _finish_cmd(cmd: bytes, id1: bytes = b'\xff', id2: bytes = b'\xff') bytes [source]
Add device ID, checksum and tail bytes.
- Parameters:
- Returns:
The command cmd after the device ID, checksum, and tail bytes have been appended.
- _get_reply() bytes | None [source]
Read reply from device.
- Returns:
The 10 bytes consisting of the device’s response.
- _process_frame(data: bytes) Tuple[float, float] [source]
Processes a SDS011 data frame.
- Byte positions:
0 - Header
1 - Command No.
2,3 - PM2.5 low/high byte
4,5 - PM10 low/high
6,7 - ID bytes
8 - Checksum - sum of bytes 2-7
9 - Tail
- Parameters:
data (bytes) – The data bytes that should be processed.
- Returns:
A tuple containing the pm25 and pm10 values queried from the device in the form (pm25, pm10).
- cmd_begin() bytes [source]
Get command header and command ID bytes.
- Returns:
The sequence of bytes corresponding to the HEAD and CMD_ID bytes as identified in the device’s data sheet.
- query() Tuple[float, float] [source]
Query the device and read the data.
- Returns:
Air particulate density in micrograms per cubic meter in the form of a tuple of floats (pm25, pm10)
- read() Tuple[float, float] [source]
Read sensor data.
- Returns:
PM25 and PM10 concentration in micrograms per cubic meter in the form (pm25, pm10).
- set_report_mode(read: bool = False, active: bool = False)[source]
Get sleep command. Does not contain checksum and tail.