Scd4x

Struct Scd4x 

Source
pub struct Scd4x<I2C, D> { /* private fields */ }
Expand description

Driver implementation for the SCD4x family of CO2 sensors. This driver is compatible with both SCD40 and SCD41 devices.

Some operations are available only for SCD41 devices. They need to be enabled via the scd41 feature flag.

Implementations§

Source§

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

Source

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

Create a new sensor using the provided I2C bus and delay implementation

Source

pub fn release(self) -> I2C

Release the I2C bus held by this sensor

Source

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

Start periodic measurement mode. The default signal update interval is 5 seconds.

Source

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

Stop periodic measurement mode to change the sensor configuration or to save power.

Note that the sensor will only respond to other commands 500 ms after the stop_periodic_measurement() command has been issued.

Source

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

Start low power periodic measurement mode, signal update interval is approximately 30 seconds.

Source

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

Check if there is a measurement data ready to be read

Source

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

Read sensor output.

The measurement data can only be read out once per signal update interval as the buffer is emptied upon read-out. If no data is available in the buffer, the sensor returns a NACK. To avoid a NACK response, the data_ready() method can be issued to check data status.

Source

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

Configure the temperature offset

Source

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

Retrieve the configured temperature offset

Source

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

Reading and writing the sensor altitude must be done while the SCD4x is in idle mode. Typically, the sensor altitude is set once after device installation. To save the setting to the EEPROM, the persist_settings() (see Section 3.9.1) command must be issued.

The default sensor altitude value is set to 0 meters above sea level. Valid input values are between 0 – 3_000 m.

Source

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

The get_sensor_altitude() command can be sent while the SCD4x is in idle mode to read out the previously saved sensor altitude value set by the set_sensor_altitude() command.

Source

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

The set_ambient_pressure() command can be sent during periodic measurements to enable continuous pressure compensation. Note that setting an ambient pressure overrides any pressure compensation based on a previously set sensor altitude. Use of this command is highly recommended for applications experiencing significant ambient pressure changes to ensure sensor accuracy. Valid input values are between 700-1200 HPa. The default value is 1013 HPa.

Source

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

The get_ambient_pressure command can be sent during periodic measurements to read out the previously saved ambient pressure value set by the set_ambient_pressure command.

Source

pub fn enable_automatic_self_calibration( &mut self, enabled: bool, ) -> Result<(), Error<E>>

Set the current state (enabled / disabled) of the ASC. By default, ASC is enabled. To save the setting to the EEPROM, the persist_settings() (see Section 3.9.1) command must be issued.

Source

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

Check if the automatic self calibration algorithm is enabled

Source

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

The set_automatic_self_calibration_target() command can be sent when the SCD4x is in idle mode. It sets the value of the ASC baseline target. This is the lower-bound background CO2 concentration the sensor is exposed to regularly. The default value is 400.

Source

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

The get_automatic_self_calibration_target() command can be sent when the SCD4x is in idle mode. It gets the value of the ASC baseline target.

Source

pub fn perform_forced_recalibration( &mut self, ppm_co2: u16, ) -> Result<Option<i16>, Error<E>>

The perform_forced_recalibration() command can be sent when the SCD4x is in idle mode after having been in operation for at least 3 minutes in an environment with a homogenous and constant CO2 concentration that is already known.

ppm_co2 refers to the current CO2 level.

An Ok(None) value indicates that the FRC has failed, because the sensor was not operated before sending the command.

An Ok(Some(_)) value indicates that the FRC was applied. It contains the magnitude of the correction

Source

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

Configuration settings such as the temperature offset, sensor altitude and the ASC enabled/disabled parameters are by default stored in the volatile memory (RAM) only and will be lost after a power-cycle. The persist_settings() command stores the current configuration in the EEPROM of the SCD4x, ensuring the settings persist across power-cycling. To avoid unnecessary wear of the EEPROM, the persist_settings() command should only be sent when persistence is required and if actual changes to the configuration have been made.

Source

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

Reading out the serial number can be used to identify the chip and to verify the presence of the sensor.

Source

pub fn sensor_variant(&mut self) -> Result<Option<SensorVariant>, Error<E>>

Source

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

The perform_self_test() command can be used as an end-of-line test to check the sensor functionality.

Source

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

The perform_factory_reset command resets all configuration settings stored in the EEPROM and erases the FRC and ASC algorithm history.

Source

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

The reinit command reinitializes the sensor by reloading user settings from EEPROM.

Before sending the reinit command, thestop_periodic_measurement() command must be issued. If the reinit command does not trigger the desired re-initialization, a power-cycle should be applied to the SCD4x.

Source

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

On-demand measurement of CO2 concentration, relative humidity and temperature. The sensor output is read out by using the read_measurement() command (Section 3.5.2).

Source

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

On-demand measurement of relative humidity and temperature only. The sensor output is read out by using the read_measurement() command (Section 3.5.2). CO2 output is returned as 0 ppm.

Source

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

Put the sensor from idle to sleep to reduce current consumption. Can be used to power down when operating the sensor in power-cycled single shot mode.

Source

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

Wake up the sensor from sleep mode into idle mode. Note that the SCD4x does not acknowledge the wake_up() command. The sensor idle state after wake up can be verified by reading out the serial number (Section 3.9.2).

Source

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

Source

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

Source

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

Source

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<I2C, D> UnwindSafe for Scd4x<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.