Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ on:
jobs:
build_and_deploy:
uses: sensirion/.github/.github/workflows/driver.python.pypi_publish.yml@main
secrets:
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}

secrets: inherit
2 changes: 2 additions & 0 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ on:
jobs:
documentation:
uses: sensirion/.github/.github/workflows/driver.python.documentation.yml@main
with:
use-project-requirements: true
11 changes: 11 additions & 0 deletions .github/workflows/gh_workflow_metadata_update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Driver Index Metadata Update

on:
push:
branches:
- main

jobs:
driver-index-metadata-update:
uses: sensirion/.github/.github/workflows/driver.common.di_metadata_update.yml@main
secrets: inherit
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.1.0] - 2026-4-30

### Changed

- Updated busy-delay from 2ms to 1ms for `enter_sleep_mode` command.
- Add `check_self_test` to examples.
## [1.0.0] - 2025-6-20

### Added

- Initial support for STCC4.

[Unreleased]: https://github.com/Sensirion/python-i2c-stcc4/compare/1.0.0...HEAD
[Unreleased]: https://github.com/Sensirion/python-i2c-stcc4/compare/1.1.0...HEAD
[1.1.0]: https://github.com/Sensirion/python-i2c-stcc4/compare/1.0.0...1.1.0
[1.0.0]: https://github.com/Sensirion/python-i2c-stcc4/releases/tag/1.0.0
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2025, Sensirion AG
Copyright (c) 2026, Sensirion AG
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ This repository contains the Python driver to communicate with a Sensirion STCC4
Click [here](https://sensirion.com/products/catalog/STCC4) to learn more about the Sensirion STCC4 sensor.


The STCC4 is Sensirion's next generation miniature CO2 sensor for indoor air quality applications.



The default I²C address of [STCC4](https://sensirion.com/products/catalog/STCC4) is **0x64**.

Expand Down
11 changes: 6 additions & 5 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html


import os
import sys
from datetime import datetime

import pkg_resources
import importlib.metadata as metadata
import sphinx.ext.autodoc

import sensirion_i2c_stcc4
Expand All @@ -17,16 +18,16 @@
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

# -- Project information -----------------------------------------------------
distribution = pkg_resources.get_distribution('sensirion_i2c_stcc4')
distribution = metadata.distribution("sensirion_i2c_stcc4")

project = u'sensirion_i2c_stcc4'
project = distribution.name
copyright = u'{} Sensirion AG, Switzerland'.format(datetime.now().year)
author = 'Sensirion AG'

# The short X.Y version
version = sensirion_i2c_stcc4.__version__
version = distribution.version
# The full version, including alpha/beta/rc tags
release = sensirion_i2c_stcc4.__version__
release = distribution.version

# -- General configuration ---------------------------------------------------

Expand Down
21 changes: 14 additions & 7 deletions examples/example_usage_linux_stcc4.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# (c) Copyright 2025 Sensirion AG, Switzerland
# (c) Copyright 2026 Sensirion AG, Switzerland
#
# THIS FILE IS AUTOMATICALLY GENERATED!
#
# Generator: sensirion-driver-generator 1.2.0
# Generator: sensirion-driver-generator 1.6.1
# Product: stcc4
# Model-Version: 3.4.0
# Model-Version: 3.5.1
#

import argparse
Expand All @@ -26,13 +26,20 @@
crc=CrcCalculator(8, 0x31, 0xff, 0x0))
sensor = Stcc4Device(channel)
sensor.stop_continuous_measurement()
(product_id, serial_number) = sensor.get_product_id()
print(f"product_id: {product_id}; serial_number: {serial_number}; ")
(product_id, serial_number
) = sensor.get_product_id()
print(f"product_id: {product_id}; "
f"serial_number: {serial_number}; "
)
test_result = sensor.check_self_test()
print(f"test_result: {test_result}; "
)
sensor.start_continuous_measurement()
for i in range(50):
time.sleep(1.0)
try:
(co2_concentration, temperature, relative_humidity, sensor_status) = sensor.read_measurement()
time.sleep(1.0)
(co2_concentration, temperature, relative_humidity, sensor_status
) = sensor.read_measurement()
except BaseException:
# Read can fail in case of clock shift, datasheet suggests to retry after 150ms
time.sleep(0.15)
Expand Down
19 changes: 12 additions & 7 deletions examples/example_usage_sensorbridge_stcc4.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# (c) Copyright 2025 Sensirion AG, Switzerland
# (c) Copyright 2026 Sensirion AG, Switzerland
#
# THIS FILE IS AUTOMATICALLY GENERATED!
#
# Generator: sensirion-driver-generator 1.2.0
# Generator: sensirion-driver-generator 1.6.1
# Product: stcc4
# Model-Version: 3.4.0
# Model-Version: 3.5.1
#

import argparse
Expand Down Expand Up @@ -40,21 +40,26 @@
print(f"product_id: {product_id}; "
f"serial_number: {serial_number}; "
)
test_result = sensor.check_self_test()
print(f"test_result: {test_result}; "
)
sensor.start_continuous_measurement()
for i in range(50):
time.sleep(1.0)
try:
(co2_concentration, temperature, relative_humidity, sensor_status) = sensor.read_measurement()
time.sleep(1.0)
(co2_concentration, temperature, relative_humidity, sensor_status
) = sensor.read_measurement()
except BaseException:
# Read can fail in case of clock shift, datasheet suggests to retry after 150ms
time.sleep(0.15)
try:
(co2_concentration, temperature, relative_humidity, sensor_status) = sensor.read_measurement()
except BaseException:
continue

print(f"co2_concentration: {co2_concentration}; "
f"temperature: {temperature}; "
f"relative_humidity: {relative_humidity}; "
f"sensor_status: {sensor_status}; "
)
f"sensor_status: {sensor_status}; ")

sensor.stop_continuous_measurement()
12 changes: 9 additions & 3 deletions examples/example_usage_single_shot_linux_stcc4.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# (c) Copyright 2025 Sensirion AG, Switzerland
# (c) Copyright 2026 Sensirion AG, Switzerland
#
# THIS FILE IS AUTOMATICALLY GENERATED!
#
# Generator: sensirion-driver-generator 1.2.0
# Generator: sensirion-driver-generator 1.6.1
# Product: stcc4
# Model-Version: 3.4.0
# Model-Version: 3.5.1
#

import argparse
Expand All @@ -31,6 +31,12 @@
sensor.exit_sleep_mode()
sensor.stop_continuous_measurement()

# Perform self-test
self_test_result = sensor.check_self_test()
if not self_test_result:
print("Self-test failed!"
)

# Enter sleep mode
sensor.enter_sleep_mode()
for i in range(100):
Expand Down
12 changes: 9 additions & 3 deletions examples/example_usage_single_shot_sensorbridge_stcc4.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# (c) Copyright 2025 Sensirion AG, Switzerland
# (c) Copyright 2026 Sensirion AG, Switzerland
#
# THIS FILE IS AUTOMATICALLY GENERATED!
#
# Generator: sensirion-driver-generator 1.2.0
# Generator: sensirion-driver-generator 1.6.1
# Product: stcc4
# Model-Version: 3.4.0
# Model-Version: 3.5.1
#

import argparse
Expand Down Expand Up @@ -40,6 +40,12 @@
sensor.exit_sleep_mode()
sensor.stop_continuous_measurement()

# Perform self-test
self_test_result = sensor.check_self_test()
if not self_test_result:
print("Self-test failed!"
)

# Enter sleep mode
sensor.enter_sleep_mode()
for i in range(100):
Expand Down
8 changes: 4 additions & 4 deletions metadata.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# driver generation metadata
generator_version: 1.2.0
model_version: 3.4.0
generator_version: 1.6.1
model_version: 3.5.1
dg_status: released
is_manually_modified: true
is_manually_modified: false
first_generated: '2025-02-24 11:47'
last_generated: '2025-06-20 08:02'
last_generated: '2026-04-30 12:17'
66 changes: 66 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
[build-system]
requires = ["hatchling >= 1.26", "wheel >= 0.45.0"]
build-backend = "hatchling.build"

[project]
name = "sensirion_i2c_stcc4"
description = "I2C driver for the Sensirion STCC4 sensor family"

readme = "README.md"
version = "1.1.0"
requires-python = ">=3.8,<4.0"

authors = [
{ name = "Sensirion", email = "info@sensirion.com" },
]

license = "BSD-3-Clause"
license-files = ["LICENSE"]

keywords = [
"Sensirion STCC4",
"I2C",
"STCC4",
]

classifiers = [
"Intended Audience :: Developers",
"Topic :: System :: Hardware :: Hardware Drivers",
"Topic :: Software Development :: Libraries :: Python Modules",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
]

dependencies = [
"sensirion-driver-adapters>=2.3.0,<3.0",
"sensirion-driver-support-types>=1.2.0,<2.0",
"sensirion-i2c-driver>=1.0,<2.0",
"sensirion-shdlc-sensorbridge>=0.1.0,<2.0"
]

[project.optional-dependencies]

docs=[
"jinja2~=3.1.6",
"sphinx-rtd-theme==3.0.2",
"sphinx==8.2.3",
"lazy-object-proxy ~=1.7.1",
"sphinx-autoapi~=3.0.0",
]

test= [
"flake8>=7.1.0",
"mock~=5.2.0",
"pytest>=8.3.5",
"pytest-cov>=5.0.0",
"mypy~=1.13.0",
"setuptools>=73.2.0"
]

[project.urls]
Changelog = "https://github.com/Sensirion/python-i2c-stcc4/blob/master/CHANGELOG.md"
Repository = "https://github.com/Sensirion/python-i2c-stcc4"
Documentation = "https://sensirion.github.io/python-i2c-stcc4"

6 changes: 3 additions & 3 deletions sensirion_i2c_stcc4/commands.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# (c) Copyright 2025 Sensirion AG, Switzerland
# (c) Copyright 2026 Sensirion AG, Switzerland
#
# THIS FILE IS AUTOMATICALLY GENERATED!
#
# Generator: sensirion-driver-generator 1.2.0
# Generator: sensirion-driver-generator 1.6.1
# Product: stcc4
# Model-Version: 3.4.0
# Model-Version: 3.5.1
#
"""
The transfer classes specify the data that is transferred between host and sensor. The generated transfer classes
Expand Down
24 changes: 20 additions & 4 deletions sensirion_i2c_stcc4/device.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# (c) Copyright 2025 Sensirion AG, Switzerland
# (c) Copyright 2026 Sensirion AG, Switzerland
#
# THIS FILE IS AUTOMATICALLY GENERATED!
#
# Generator: sensirion-driver-generator 1.2.0
# Generator: sensirion-driver-generator 1.6.1
# Product: stcc4
# Model-Version: 3.4.0
# Model-Version: 3.5.1
#
"""
The class Stcc4DeviceBase implements the low level interface of the sensor.
Expand Down Expand Up @@ -249,7 +249,7 @@ def __init__(self, channel):

def read_measurement(self):
"""
reads measurement data
Reads measurement data from the sensor and returns the CO2 concentration in ppm, the temperature in °C, the relative humidity in %RH and the sensor status.

:return co2_concentration:

Expand All @@ -275,3 +275,19 @@ def set_pressure_compensation(self, pressure):

"""
self.stcc4.set_pressure_compensation_raw(int(pressure / 2))

def check_self_test(self):
"""
Check if the self-test is successful.

:return test_result:

"""
self_test_result = 0
try:
self_test_result = self.stcc4.perform_self_test()

except: # noqa
return False

return self_test_result == 0
Loading
Loading