Skip to main content

Scd41

Struct Scd41 

Source
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>

Source

pub fn new(i2c: I2C, delay: D) -> Self

Create a new driver using the default I2C address (0x62).

Source

pub fn new_with_address(i2c: I2C, delay: D, address: u8) -> Self

Create a new driver using a custom I2C address.

Source

pub fn destroy(self) -> I2C

Destroy the driver and return the underlying I2C bus.

Source§

impl<I2C, D, E> Scd41<I2C, D>
where I2C: I2c<Error = E>, D: DelayNs,

Source

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
Source

pub fn stop_periodic_measurement(&mut self) -> Result<(), Error<E>>

Stop periodic measurement.

Source

pub fn data_ready(&mut self) -> Result<bool, Error<E>>

Returns true if a new measurement is available.

Source

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.

Source

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.

Source

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.

Source

pub fn measure_single_shot_rht_only(&mut self) -> Result<(), Error<E>>

Perform a single-shot temperature+humidity-only measurement.

Source

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).

Source

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.

Source

pub fn serial_number(&mut self) -> Result<u64, Error<E>>

Read 48-bit serial number.

Source

pub fn temperature_offset(&mut self) -> Result<f32, Error<E>>

Get temperature offset in °C.

Source

pub fn set_temperature_offset(&mut self, offset_c: f32) -> Result<(), Error<E>>

Set temperature offset in °C.

Source

pub fn altitude(&mut self) -> Result<u16, Error<E>>

Get configured altitude (m above sea level).

Source

pub fn set_altitude(&mut self, meters: u16) -> Result<(), Error<E>>

Set configured altitude (m above sea level).

Source

pub fn set_ambient_pressure( &mut self, pressure_hpa: u16, ) -> Result<(), Error<E>>

Set ambient pressure in hPa.

Source

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.

Source

pub fn automatic_self_calibration(&mut self) -> Result<bool, Error<E>>

Get ASC enabled/disabled.

Source

pub fn persist_settings(&mut self) -> Result<(), Error<E>>

Persist settings to EEPROM.

Source

pub fn reinit(&mut self) -> Result<(), Error<E>>

Reinitialize by reloading user settings from EEPROM.

Source

pub fn self_test_is_ok(&mut self) -> Result<bool, Error<E>>

Run the built-in self test. Returns true if OK.

Source

pub fn factory_reset(&mut self) -> Result<(), Error<E>>

Factory reset.

Source

pub fn forced_recalibration( &mut self, target_co2_ppm: u16, ) -> Result<u16, Error<E>>

Perform forced recalibration.

Returns the correction value.

Trait Implementations§

Source§

impl<I2C: Debug, D: Debug> Debug for Scd41<I2C, D>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<I2C, D> Freeze for Scd41<I2C, D>
where I2C: Freeze, D: Freeze,

§

impl<I2C, D> RefUnwindSafe for Scd41<I2C, D>

§

impl<I2C, D> Send for Scd41<I2C, D>
where I2C: Send, D: Send,

§

impl<I2C, D> Sync for Scd41<I2C, D>
where I2C: Sync, D: Sync,

§

impl<I2C, D> Unpin for Scd41<I2C, D>
where I2C: Unpin, D: Unpin,

§

impl<I2C, D> UnwindSafe for Scd41<I2C, D>
where I2C: UnwindSafe, D: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.