/sensirion-sen5x

Full support for Sensirion SEN5x sensors

Primary LanguagePythonMIT LicenseMIT

Sensirion SEN5x Micropython Driver

Provides access from ESP32-C3 to all Sensirion SEN5x capability via I2C.

Built With

Tested with the following; "should" work with similar setups.

Sample Usage

from machine import I2C, Pin
from sen5x.sen5x import SEN5x

"""
    Wiring:
        ESP32 Pin 7 ------- SEN5x SCL (internal or external pull-up to 3V3)
        ESP32 Pin 6 ------- SEN5x SDA (internal or external pull-up to 3V3)
        ESP32 5V    ------- SEN5x 5V
        ESP32 GND   ------- SEN5x GND
        ESP32 GND   ------- SEN5x SEL       
"""
ID = 0
SCL_PIN_NUM = 7
SDA_PIN_NUM = 6
FREQ = 50000  # see https://github.com/micropython/micropython/issues/7772

i2c = I2C(ID,
          scl=Pin(SCL_PIN_NUM, pull=Pin.PULL_UP),  # internal pull-up
          sda=Pin(SDA_PIN_NUM, pull=Pin.PULL_UP),  # internal pull-up
          freq=FREQ)

with SEN5x(i2c) as sen:
    print('Product Name:', sen.product_name)
    print('Serial Number:', sen.serial_number)
    print('Data Ready:', sen.data_ready)
    ppm1_0, ppm2_5, ppm4_0, ppm10_0, rh, t, voc, nox = sen.measured_values
    print('PPM 1.0:', ppm1_0, 'PPM 2.5:', ppm2_5, 'PPM 4.0:', ppm4_0, 'PPM 10.0:', ppm10_0)
    print('Humidity:', rh, 'Temp:', t, 'VOC:', voc, 'NOx:', nox)

Code Samples

Getting Started

  1. Setup ESP32
  2. Wire ESP32-C3-DevKitM-1 to Sensirion SEN5x following Wiring comment in examples/main.py
  3. Configure SCL_PIN_NUM, SDA_PIN_NUM in examples/main.py
  4. Copy files to ESP32 root directory
    • examples/main.py -> /pyboard/main.py
    • sen5x/sen5x.py -> /pyboard/lib/sen5x/sen5x.py
    • tools/tools.py -> /pyboard/lib/tools/tools.py
  5. Start REPL
  6. Boot ESP32

I found rshell to be useful.

Documentation

Refer to Sensirion SEN5x Datasheet for property, method & argument details.

SEN5x properties

Property Has
Setter?
Type(s)
product_name no str
serial_number no str
firmware_version no int
data_ready no bool
measured_values no tuple
- ppm 1.0: int
- ppm 2.5: int
- ppm 4.0: int
- ppm 10.0: int
- temperature °C: float
- humidity: int
- voc index: int
- nox index: int
measured_values_imperial no tuple
- ppm 1.0: int
- ppm 2.5: int
- ppm 4.0: int
- ppm 10.0: int
- temperature°F: int
- humidity: int
- voc index: int
- nox index: int
measured_values_raw no tuple
- ppm 1.0: float
- ppm 2.5: float
- ppm 4.0: float
- ppm 10.0: float
- temperature: float
- humidity: float
- voc index: float
- nox index: float
temperature_compensation_params yes tuple
- offset: float
- slope: float
- time const: int
warm_start_param yes int
voc_algorithm_tuning_params yes tuple
- index offset: int
- time offset: int
- time gain: int
- max duration: int
- std initial: int
- gain factor: int
nox_algorithm_tuning_params yes tuple
- index offset: int
- time offset: int
- time gain: int
- max duration: int
- std initial: int
- gain factor: int
rht_acceleration_mode yes int
voc_algorithm_state yes bytes(8)
auto_cleaning_interval yes int
status no int
fan_cleaning_active no bool

SEN5x methods

Method Args Return
start() None None
stop() None None
start_measurement() num checks: int = 100 ready: bool
start_measurement_rht_gas_only_mode() num checks: int = 100 ready: bool
stop_measurement() None None
backup_voc_algorithm_state() None None
restore_voc_algorithm_state() None None
purge_backup_voc_algorithm_state() None None
start_fan_cleaning() None None
check_i2c() None None
Raises SEN5x.NotFoundError
check_for_errors() None None
Raises SEN5x.StatusError
clear_status() None None
reset() None None

License

This project is released under the MIT License.