STCC4 Rust Driver
A Rust no-std driver for the Sensirion STCC4 CO2 sensor with blocking and async APIs.
Description
This library provides a platform-agnostic Rust interface for the STCC4 CO2 sensor over I2C. It is designed for embedded, no-std environments and supports both blocking and async access patterns based on embedded-hal and embedded-hal-async.
Supported features
All supported features are available in both blocking and async mode.
- Start/stop continuous measurement
- Single-shot measurement
- Read measurement data (CO2, temperature, humidity, status)
- Set RHT compensation values (external sensor)
- Set pressure compensation
- Sleep / wake
- Conditioning
- Soft reset (general call)
- Factory reset
- Self test
- Enable/disable testing mode
- Forced recalibration (FRC)
- Read product ID and serial number
Rust features
async(default): Enables async support usingembedded-hal-asyncdefmt: Enablesdefmt::Formatderives and addsdefmtlogging statementsserde: Enablesserdesupport for public data types (no std features)
Dependencies
embedded-halfor blocking I2C and delaysembedded-hal-asyncfor async I2C and delays (gated byasyncfeature)defmtandserdeare optional and controlled by features
For tests, the crate uses embedded-hal-mock and a minimal async mock implementation.
Usage
Add the crate to your Cargo.toml:
[]
= "0.1.0"
Blocking example
use Stcc4;
# # where
# D: DelayNs,
# I2C: I2c,
#
Async example
use Stcc4;
# async # where
# D: DelayNs,
# I2C: I2c,
#
Testing
Run unit tests:
Generate coverage (HTML):
Notes
- Default I2C address is
0x64, alternate is0x65. - The
exit_sleep_modeandperform_soft_resetcommands are not acknowledged by the sensor, and the driver handles this accordingly. - Temperature and humidity values in measurements are reported by an external SHT4x sensor; use
set_rht_compensationif not using the STCC4’s dedicated controller interface for SHT4x.
Links
- Datasheet: https://sensirion.com/resource/datasheet/STCC4 (developed on datasheet version 1)
License
This library is licensed under either of:
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this work is dual licensed as above, without any additional terms or conditions.
Change Log
- Version 0.1.0 - Initial release