diff --git a/Cargo.lock b/Cargo.lock index 7108237..a6d1345 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2000,8 +2000,7 @@ dependencies = [ [[package]] name = "scd4x" version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "550fedc97e7880654aa7dc840f5eb3b2201a01aae566c4584a3601bb0086cd4c" +source = "git+https://github.com/twokilohertz/scd4x-rs.git?branch=self-calib-tgt#3ec7b975b32ed8ec47c71ecee3711f430871bd2e" dependencies = [ "embedded-hal 1.0.0", "log", diff --git a/Cargo.toml b/Cargo.toml index bc3e3b2..65fb3f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,7 +44,7 @@ embedded-graphics = "0.8.1" embedded-graphics-framebuf = "0.5.0" # Peripherals -scd4x = { version = "0.4.0", features = ["scd41"] } +scd4x = { git = "https://github.com/twokilohertz/scd4x-rs.git", branch = "self-calib-tgt", features = ["scd41"] } ssd1351 = "0.5.0" display-interface-spi = "0.5.0" diff --git a/src/sensor_task.rs b/src/sensor_task.rs index 97f960e..d7c9199 100644 --- a/src/sensor_task.rs +++ b/src/sensor_task.rs @@ -8,11 +8,15 @@ use scd4x::Scd4x; use crate::{I2c0BusMutex, SENSOR_DATA_SIGNAL}; +const BACKGROUND_CO2_PPM: u16 = 427; + /// Read CO2/temp./humidity data from the sensor #[embassy_executor::task] pub async fn sensor_read_task(i2c_bus: &'static I2c0BusMutex) { debug_rprintln!("Sensor read task started"); + // Initialise SCD41 + Timer::after_millis(30).await; // SCD41 power-up delay let i2c_dev = I2cDevice::new(i2c_bus); @@ -20,6 +24,11 @@ pub async fn sensor_read_task(i2c_bus: &'static I2c0BusMutex) { scd41.wake_up(); scd41.reinit().unwrap(); + // https://climate.nasa.gov/vital-signs/carbon-dioxide/?intent=121 + scd41 + .set_automatic_self_calibration_target(BACKGROUND_CO2_PPM) + .unwrap(); + match scd41.serial_number() { Ok(serial) => debug_rprintln!("[SCD41] Serial number: {}", serial), Err(error) => debug_rprintln!( @@ -28,6 +37,8 @@ pub async fn sensor_read_task(i2c_bus: &'static I2c0BusMutex) { ), } + // Measurement loop + scd41.start_periodic_measurement().unwrap(); loop { @@ -53,4 +64,6 @@ pub async fn sensor_read_task(i2c_bus: &'static I2c0BusMutex) { } } } + + scd41.stop_periodic_measurement().unwrap(); }