Execute measurements with SensorBridge
The following steps show how to use this driver on a Windows system using the Sensirion SEK-SensorBridge to execute a simple measurement.
Install the SCD4X driver and all required packages as described in Installation.
Install the driver for the Sensirion SEK-SensorBridge
pip install sensirion-shdlc-sensorbridge
Connect the SEK-SensorBridge to your PC over USB
If the SEK-SensorBridge is not detected by your system, follow the SensorBridge FTDI Driver Installation
Connect the SCD4X sensor to the SEK-SensorBridge
Run the example script from the root of the repository.
By default the script assumes the SensorBridge 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_sensorbridge_scd4x.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.1.2
# Product: scd4x
# Model-Version: 2.0
#
import argparse
import time
from sensirion_i2c_driver import I2cConnection, CrcCalculator
from sensirion_shdlc_driver import ShdlcSerialPort, ShdlcConnection
from sensirion_shdlc_sensorbridge import (SensorBridgePort,
SensorBridgeShdlcDevice,
SensorBridgeI2cProxy)
from sensirion_driver_adapters.i2c_adapter.i2c_channel import I2cChannel
from sensirion_i2c_scd4x.device import Scd4xDevice
parser = argparse.ArgumentParser()
parser.add_argument('--serial-port', '-p', default='COM1')
args = parser.parse_args()
with ShdlcSerialPort(port=args.serial_port, baudrate=460800) as port:
bridge = SensorBridgeShdlcDevice(ShdlcConnection(port), slave_address=0)
bridge.set_i2c_frequency(SensorBridgePort.ONE, frequency=100e3)
bridge.set_supply_voltage(SensorBridgePort.ONE, voltage=3.3)
bridge.switch_supply_on(SensorBridgePort.ONE)
i2c_transceiver = SensorBridgeI2cProxy(bridge, port=SensorBridgePort.ONE)
channel = I2cChannel(I2cConnection(i2c_transceiver),
slave_address=0x62,
crc=CrcCalculator(8, 0x31, 0xff, 0x0))
sensor = Scd4xDevice(channel)
time.sleep(0.03)
# Ensure sensor is in clean state
sensor.wake_up()
sensor.stop_periodic_measurement()
sensor.reinit()
# Read out information about the sensor
serial_number = sensor.get_serial_number()
print(f"serial number: {serial_number}"
)
# If temperature offset and/or sensor altitude compensation
# is required, you should call the respective functions here.
# Check out the header file for the function definitions.
# Start periodic measurements (5sec interval)
sensor.start_periodic_measurement()
# If low-power mode is required, switch to the low power
# measurement function instead of the standard measurement
# function above. Check out the header file for the definition.
# For SCD41, you can also check out the single shot measurement example.
for i in range(50):
# Slow down the sampling to 0.2Hz.
time.sleep(5.0)
data_ready = sensor.get_data_ready_status()
while not data_ready:
time.sleep(0.1)
data_ready = sensor.get_data_ready_status()
# If ambient pressure compenstation during measurement
# is required, you should call the respective functions here.
# Check out the header file for the function definition.
(co2_concentration, temperature, relative_humidity
) = sensor.read_measurement()
# Print results in physical units.
print(f"CO2 concentration [ppm]: {co2_concentration}"
)
print(f"Temperature [°C]: {temperature}"
)
print(f"Relative Humidity [RH]: {relative_humidity}"
)
Execute measurements using internal Linux I²C driver
On Linux systems it is furthermore possible to use the Linux user space I²C driver directly. How this can be done is shown in the following.
Install the SCD4X driver and all required packages as described in Installation.
Connect the SCD4X sensor to the I²C port of your system (for example to the I²C port 1 of a Raspberry Pi).
Run the example script from the root of the repository.
By default the script assumes you have the sensor connected to
/dev/i2c-1
. If this is different on your system, pass the port in use with the--i2c-port
parameter as outlined below.python examples/example_usage_linux_scd4x.py --i2c-port <your I2C 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.1.2
# Product: scd4x
# Model-Version: 2.0
#
import argparse
import time
from sensirion_i2c_driver import LinuxI2cTransceiver, I2cConnection, CrcCalculator
from sensirion_driver_adapters.i2c_adapter.i2c_channel import I2cChannel
from sensirion_i2c_scd4x.device import Scd4xDevice
parser = argparse.ArgumentParser()
parser.add_argument('--i2c-port', '-p', default='/dev/i2c-1')
args = parser.parse_args()
with LinuxI2cTransceiver(args.i2c_port) as i2c_transceiver:
channel = I2cChannel(I2cConnection(i2c_transceiver),
slave_address=0x62,
crc=CrcCalculator(8, 0x31, 0xff, 0x0))
sensor = Scd4xDevice(channel)
time.sleep(0.03)
# Ensure sensor is in clean state
sensor.wake_up()
sensor.stop_periodic_measurement()
sensor.reinit()
# Read out information about the sensor
serial_number = sensor.get_serial_number()
print(f"serial number: {serial_number}"
)
# If temperature offset and/or sensor altitude compensation
# is required, you should call the respective functions here.
# Check out the header file for the function definitions.
# Start periodic measurements (5sec interval)
sensor.start_periodic_measurement()
# If low-power mode is required, switch to the low power
# measurement function instead of the standard measurement
# function above. Check out the header file for the definition.
# For SCD41, you can also check out the single shot measurement example.
for i in range(50):
# Slow down the sampling to 0.2Hz.
time.sleep(5.0)
data_ready = sensor.get_data_ready_status()
while not data_ready:
time.sleep(0.1)
data_ready = sensor.get_data_ready_status()
# If ambient pressure compenstation during measurement
# is required, you should call the respective functions here.
# Check out the header file for the function definition.
(co2_concentration, temperature, relative_humidity
) = sensor.read_measurement()
# Print results in physical units.
print(f"CO2 concentration [ppm]: {co2_concentration}"
)
print(f"Temperature [°C]: {temperature}"
)
print(f"Relative Humidity [RH]: {relative_humidity}"
)