Skip to content

getting started

tim-oe edited this page Apr 3, 2026 · 4 revisions

Getting Started

Installation

pip install sonic-modbus

Hardware

Quick Example

Connect over Modbus RTU (default 4800 baud, 8N1, device address 1 — see the hardware wiki). Adjust port for your system (/dev/ttyUSB0, /dev/ttyAMA0, COM3, …).

from sonic_modbus import SonicSensor

with SonicSensor(port="/dev/ttyUSB0") as sensor:
    r = sensor.read()
    print(f"Wind: {r.wind_speed_ms} m/s {r.wind_direction.name} ({r.wind_angle_deg}°)")
    print(f"Temp: {r.temperature_c} °C, humidity: {r.humidity_pct} %RH")
    print(f"Pressure: {r.atm_pressure_kpa} kPa, light: {r.light_lux} lux")
    print(f"PM2.5: {r.pm25_ugm3} µg/m³, PM10: {r.pm10_ugm3} µg/m³, rain: {r.rainfall_mm} mm")

read() raises pymodbus.ModbusException if the bus read fails; ensure the sensor is wired and the port/baud/device id match the module.

Clone this wiki locally