Compare commits

...

2 Commits

3 changed files with 18 additions and 5 deletions

8
Cargo.lock generated
View File

@@ -1360,9 +1360,9 @@ dependencies = [
[[package]]
name = "log"
version = "0.4.26"
version = "0.4.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30bde2b3dc3671ae49d8e2e9f044c7c005836e7a023ee57cffa25ab82764bb9e"
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
[[package]]
name = "memchr"
@@ -1999,9 +1999,9 @@ dependencies = [
[[package]]
name = "scd4x"
version = "0.4.0"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "550fedc97e7880654aa7dc840f5eb3b2201a01aae566c4584a3601bb0086cd4c"
checksum = "455974f1daa137284e9e282362d1074f004028a77ee84c6bb1508c9e89646153"
dependencies = [
"embedded-hal 1.0.0",
"log",

View File

@@ -44,7 +44,7 @@ embedded-graphics = "0.8.1"
embedded-graphics-framebuf = "0.5.0"
# Peripherals
scd4x = { version = "0.4.0", features = ["scd41"] }
scd4x = { version = "0.4.1", features = ["scd41"] }
ssd1351 = "0.5.0"
display-interface-spi = "0.5.0"

View File

@@ -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();
}