Execute measurements
The following steps show how to use this driver to execute a simple measurement on a Windows system.
Install the SPS30 sensor driver and all required packages as described in Installation.
Connect the SPS30 sensor to your system with the serial USB cable.
Run the example script from the root of the repository.
By default the script assumes the sensor is connected to COM1 serial port. If this is different on your system, pass the port in use with the
--serial-port
parameter as outlined below.python examples/example_usage_uart_sps30.py --serial-port <your COM port>
Example script
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# (c) Copyright 2025 Sensirion AG, Switzerland
#
# THIS FILE IS AUTOMATICALLY GENERATED!
#
# Generator: sensirion-driver-generator 1.3.3
# Product: sps30
# Model-Version: 1.0.1
#
import time
import argparse
from sensirion_shdlc_driver import ShdlcSerialPort
from sensirion_driver_adapters.shdlc_adapter.shdlc_channel import ShdlcChannel
from sensirion_uart_sps30.device import Sps30Device
from sensirion_uart_sps30.commands import (OutputFormat)
parser = argparse.ArgumentParser()
parser.add_argument('--serial-port', '-p', default='COM1')
args = parser.parse_args()
with ShdlcSerialPort(port=args.serial_port, baudrate=115200, additional_response_time=0.02) as port:
channel = ShdlcChannel(port)
sensor = Sps30Device(channel)
try:
sensor.stop_measurement()
except BaseException:
...
serial_number = sensor.read_serial_number()
print(f"serial_number: {serial_number}; "
)
product_type = sensor.read_product_type()
print(f"product_type: {product_type}; "
)
sensor.start_measurement(OutputFormat(261))
for i in range(50):
try:
time.sleep(1.0)
(mc_1p0, mc_2p5, mc_4p0, mc_10p0, nc_0p5, nc_1p0, nc_2p5, nc_4p0, nc_10p0, typical_particle_size
) = sensor.read_measurement_values_uint16()
print(f"mc_1p0: {mc_1p0}; "
f"mc_2p5: {mc_2p5}; "
f"mc_4p0: {mc_4p0}; "
f"mc_10p0: {mc_10p0}; "
f"nc_0p5: {nc_0p5}; "
f"nc_1p0: {nc_1p0}; "
f"nc_2p5: {nc_2p5}; "
f"nc_4p0: {nc_4p0}; "
f"nc_10p0: {nc_10p0}; "
f"typical_particle_size: {typical_particle_size}; "
)
except BaseException:
continue
sensor.stop_measurement()