pub struct Scd41<I2C, D> { /* private fields */ }Expand description
Blocking SCD41 driver. This is your main interface to the sensor.
§Example
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()?;
// ... do some other operations
}Implementations§
Source§impl<I2C, D> Scd41<I2C, D>
impl<I2C, D> Scd41<I2C, D>
Sourcepub fn new(i2c: I2C, delay: D) -> Self
pub fn new(i2c: I2C, delay: D) -> Self
Create a new driver using the default I2C address (0x62).
Sourcepub fn new_with_address(i2c: I2C, delay: D, address: u8) -> Self
pub fn new_with_address(i2c: I2C, delay: D, address: u8) -> Self
Create a new driver using a custom I2C address.
Source§impl<I2C, D, E> Scd41<I2C, D>
impl<I2C, D, E> Scd41<I2C, D>
Sourcepub fn start_periodic_measurement(&mut self) -> Result<(), Error<E>>
pub fn start_periodic_measurement(&mut self) -> Result<(), Error<E>>
Start periodic measurement (data update ~ every 5 seconds).
§Use Case
You use periodic measurement when your application needs continuous, automatically updated CO₂ data with minimal firmware control and good real-time responsiveness. Some examples of this would be:
- You need fast response to CO₂ changes
- Power consumption is not critical
- You want simpler firmware
- You want automatic self-calibration behavior
Sourcepub fn stop_periodic_measurement(&mut self) -> Result<(), Error<E>>
pub fn stop_periodic_measurement(&mut self) -> Result<(), Error<E>>
Stop periodic measurement.
Sourcepub fn data_ready(&mut self) -> Result<bool, Error<E>>
pub fn data_ready(&mut self) -> Result<bool, Error<E>>
Returns true if a new measurement is available.
Sourcepub fn measurement(&mut self) -> Result<Measurement, Error<E>>
pub fn measurement(&mut self) -> Result<Measurement, Error<E>>
Read the latest measurement and returns the processed values. This will fail if the periodic measurement has not been started via start_periodic_measurement.
Sourcepub fn raw_measurement(&mut self) -> Result<RawMeasurement, Error<E>>
pub fn raw_measurement(&mut self) -> Result<RawMeasurement, Error<E>>
Read raw measurement words.
Returns CO₂ in ppm, raw temperature ticks, and raw humidity ticks. A typical user should use the measurement method instead.
Sourcepub fn measure_single_shot(&mut self) -> Result<(), Error<E>>
pub fn measure_single_shot(&mut self) -> Result<(), Error<E>>
Perform a single-shot measurement (takes ~5 seconds).
After performing the measurement, read the results with measurement or raw_measurement.
Sourcepub fn measure_single_shot_rht_only(&mut self) -> Result<(), Error<E>>
pub fn measure_single_shot_rht_only(&mut self) -> Result<(), Error<E>>
Perform a single-shot temperature+humidity-only measurement.
Sourcepub fn power_down(&mut self) -> Result<(), Error<E>>
pub fn power_down(&mut self) -> Result<(), Error<E>>
Put the sensor to sleep. This operation takes about 1ms.
Power-cycled mode only makes sense if sampling periods are > ~380 s (~6 min).
Sourcepub fn wake_up_best_effort(&mut self)
pub fn wake_up_best_effort(&mut self)
Wake the sensor. This operation takes about 20ms on the sensor. This function will not wait for the full wake-up time but rather simply initialize the wake-up command. Note that after calling this function, you should wait at least 20ms and discard the first measurement results.
Sourcepub fn serial_number(&mut self) -> Result<u64, Error<E>>
pub fn serial_number(&mut self) -> Result<u64, Error<E>>
Read 48-bit serial number.
Sourcepub fn temperature_offset(&mut self) -> Result<f32, Error<E>>
pub fn temperature_offset(&mut self) -> Result<f32, Error<E>>
Get temperature offset in °C.
Sourcepub fn set_temperature_offset(&mut self, offset_c: f32) -> Result<(), Error<E>>
pub fn set_temperature_offset(&mut self, offset_c: f32) -> Result<(), Error<E>>
Set temperature offset in °C.
Sourcepub fn altitude(&mut self) -> Result<u16, Error<E>>
pub fn altitude(&mut self) -> Result<u16, Error<E>>
Get configured altitude (m above sea level).
Sourcepub fn set_altitude(&mut self, meters: u16) -> Result<(), Error<E>>
pub fn set_altitude(&mut self, meters: u16) -> Result<(), Error<E>>
Set configured altitude (m above sea level).
Sourcepub fn set_ambient_pressure(
&mut self,
pressure_hpa: u16,
) -> Result<(), Error<E>>
pub fn set_ambient_pressure( &mut self, pressure_hpa: u16, ) -> Result<(), Error<E>>
Set ambient pressure in hPa.
Sourcepub fn set_automatic_self_calibration(
&mut self,
enabled: bool,
) -> Result<(), Error<E>>
pub fn set_automatic_self_calibration( &mut self, enabled: bool, ) -> Result<(), Error<E>>
Enable/disable ASC.
Note that the ASC will not work when you power-cycle between readings. Long-term accuracy may drift unless you manually recalibrate.
Sourcepub fn automatic_self_calibration(&mut self) -> Result<bool, Error<E>>
pub fn automatic_self_calibration(&mut self) -> Result<bool, Error<E>>
Get ASC enabled/disabled.
Sourcepub fn persist_settings(&mut self) -> Result<(), Error<E>>
pub fn persist_settings(&mut self) -> Result<(), Error<E>>
Persist settings to EEPROM.
Sourcepub fn reinit(&mut self) -> Result<(), Error<E>>
pub fn reinit(&mut self) -> Result<(), Error<E>>
Reinitialize by reloading user settings from EEPROM.
Sourcepub fn self_test_is_ok(&mut self) -> Result<bool, Error<E>>
pub fn self_test_is_ok(&mut self) -> Result<bool, Error<E>>
Run the built-in self test. Returns true if OK.
Sourcepub fn factory_reset(&mut self) -> Result<(), Error<E>>
pub fn factory_reset(&mut self) -> Result<(), Error<E>>
Factory reset.