Skip to main content

percepter_scd41/
lib.rs

1//! # SCD41 CO2 Sensor Driver
2//!
3//! This crate provides a driver for the SCD41 CO2 sensor from Sensirion.
4//! It uses `embedded-hal` for I2C communication and timing.
5//!
6//! ## Example
7//! ```no_run
8//! use percepter_scd41::SCD41;
9//!
10//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
11//! // Here, you can use any I2C and Delay implementation from `embedded-hal`.
12//! // For example, `linux-embedded-hal` for Linux systems:
13//! // use linux_embedded_hal::{Delay, I2cdev};
14//! // let i2c = I2cdev::new("/dev/i2c-1")?;
15//! // let mut scd41 = SCD41::new_with_default_address(i2c, Delay);
16//!
17//! # // (Simplified example for demonstration)
18//! # use embedded_hal_mock::eh1::i2c::{Mock as I2cMock, Transaction as I2cTrans};
19//! # use embedded_hal_mock::eh1::delay::NoopDelay as Delay;
20//! # let i2c = I2cMock::new(&[]);
21//! # let mut scd41 = SCD41::new_with_default_address(i2c, Delay);
22//!
23//! // Start periodic measurement
24//! scd41.start_periodic_measurement()?;
25//!
26//! loop {
27//!     if scd41.data_ready()? {
28//!         let measurement = scd41.read_measurement()?;
29//!         println!("CO2: {} ppm", measurement.co2());
30//!         println!("Temperature: {:.1} °C", measurement.temperature());
31//!         println!("Humidity: {:.1} %RH", measurement.relative_humidity());
32//!     }
33//!     // SCD41 updates every 5 seconds in periodic mode
34//!     std::thread::sleep(std::time::Duration::from_secs(5));
35//! }
36//! # Ok(())
37//! # }
38//! ```
39//!
40//! ## Features
41//! - Periodic and Single Shot measurement modes.
42//! - Low power periodic measurement mode.
43//! - Ambient pressure and altitude compensation.
44//! - Temperature offset calibration.
45//! - Forced recalibration (FRC) and Automatic Self-Calibration (ASC).
46//! - Power down and wake up for power saving.
47
48mod crc;
49mod measurement;
50pub mod error;
51pub mod scd41;
52pub use measurement::Measurement;
53pub use crate::scd41::SCD41;