Expand description
no_std driver for the Sensirion SCD41 CO₂ / temperature / humidity sensor.
scd41-embedded is a small, no_std driver for the Sensirion SCD41 (SCD4x family),
built on top of the embedded-hal traits.
This crate is a clean reimplementation inspired by existing Rust work in this space
(notably scd4x: https://github.com/hauju/scd4x-rs), while following the same async feature
conventions used by the other drivers in this workspace.
§What this crate provides
- A blocking driver:
Scd41 - Basic configuration + measurement methods
- Optional async API behind the
asyncfeature: [r#async::Scd41Async]
§Blocking usage
use scd41_embedded::{Error, Scd41};
fn example<I2C, D, E>(i2c: I2C, delay: D) -> Result<(), Error<E>>
where
I2C: embedded_hal::i2c::I2c<Error = E>,
D: embedded_hal::delay::DelayNs,
E: embedded_hal::i2c::Error,
{
let mut scd = Scd41::new(i2c, delay);
scd.start_periodic_measurement()?;
loop {
if scd.data_ready()? {
let m = scd.measurement()?;
// m.co2_ppm
// m.temperature_c
// m.relative_humidity_percent
break;
}
}
Ok(())
}§Async usage
Enable the async feature to use the async driver API in [r#async].
The async API uses embedded-hal-async and
requires async implementations of both I2c and DelayNs.
use scd41_embedded::{Error};
use scd41_embedded::r#async::Scd41Async;
pub async fn example<I2C, D, E>(i2c: I2C, delay: D) -> Result<(), Error<E>>
where
I2C: embedded_hal_async::i2c::I2c<Error = E>,
D: embedded_hal_async::delay::DelayNs,
E: embedded_hal::i2c::Error,
{
let mut scd = Scd41Async::new(i2c, delay);
scd.start_periodic_measurement().await?;
loop {
if scd.data_ready().await? {
let _m = scd.measurement().await?;
break;
}
}
Ok(())
}§Notes
- The SCD41 uses a per-word CRC byte (Sensirion CRC-8). This crate validates CRCs on reads.
- Some commands are not intended to be used while periodic measurement is running.
Modules§
- types
- Data types.
Structs§
- Scd41
- Blocking SCD41 driver. This is your main interface to the sensor.
Enums§
- Error
- Driver error.
Constants§
- DEFAULT_
ADDRESS - Default 7-bit I2C address of the SCD41.