Quick Start

In order to correctly select I²C as interface, the interface select pin must be pulled low to GND before or at the same time the sensor is powered up.

Linux I²C Bus Example

Following example code shows how to use this driver with a Sensirion SVM41 connected to a Linux I²C bus (e.g. Raspberry Pi).

import time
from sensirion_i2c_driver import I2cConnection, LinuxI2cTransceiver
from sensirion_i2c_svm41 import Svm41I2cDevice


with LinuxI2cTransceiver('/dev/i2c-1') as i2c_transceiver:
    device = Svm41I2cDevice(I2cConnection(i2c_transceiver))
    device.device_reset()

    # Print some device information
    print("Version: {}".format(device.get_version()))
    print("Serial Number: {}".format(device.get_serial_number()))

    # Start measurement
    device.start_measurement()
    print("Measurement started... ")
    while True:
        time.sleep(10.)
        humidity, temperature, air_quality_voc, air_quality_nox = \
            device.read_measured_values()

        # use default formatting for printing output:
        print("{}, {}, {}, {}".format(humidity,
                                      temperature,
                                      air_quality_voc,
                                      air_quality_nox))

SensorBridge Example

Following example code shows how to use this driver with a Sensirion SVM41 connected to the computer using a Sensirion SEK-SensorBridge. The driver for the SensorBridge can be installed with pip install sensirion-shdlc-sensorbridge.

import time
from sensirion_shdlc_driver import ShdlcSerialPort, ShdlcConnection
from sensirion_shdlc_sensorbridge import SensorBridgePort, \
    SensorBridgeShdlcDevice, SensorBridgeI2cProxy
from sensirion_i2c_driver import I2cConnection
from sensirion_i2c_svm41 import Svm41I2cDevice

# Connect to the SensorBridge with default settings:
#  - baudrate:      460800
#  - slave address: 0
with ShdlcSerialPort(port='COM1', baudrate=460800) as port:
    bridge = SensorBridgeShdlcDevice(ShdlcConnection(port), slave_address=0)
    print("SensorBridge SN: {}".format(bridge.get_serial_number()))

    # Configure SensorBridge port 1 for SVM41
    bridge.set_i2c_frequency(SensorBridgePort.ONE, frequency=100e3)
    bridge.set_supply_voltage(SensorBridgePort.ONE, voltage=3.3)
    bridge.switch_supply_on(SensorBridgePort.ONE)

    # Create SVM41 device
    i2c_transceiver = SensorBridgeI2cProxy(bridge, port=SensorBridgePort.ONE)
    device = Svm41I2cDevice(I2cConnection(i2c_transceiver))

    # Print some device information
    print("Version: {}".format(device.get_version()))
    print("Serial Number: {}".format(device.get_serial_number()))

    # Start measurement
    device.start_measurement()
    print("Measurement started... ")
    while True:
        time.sleep(10.)
        humidity, temperature, air_quality_voc, air_quality_nox = \
            device.read_measured_values()

        # use default formatting for printing output:
        print("{}, {}, {}, {}".format(humidity,
                                      temperature,
                                      air_quality_voc,
                                      air_quality_nox))