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>
impl<I2C, D, E> Scd4x<I2C, D>
Sourcepub fn new(i2c: I2C, delay: D) -> Self
pub fn new(i2c: I2C, delay: D) -> Self
Create a new sensor using the provided I2C bus and delay implementation
Sourcepub fn start_periodic_measurement(&mut self) -> Result<(), Error<E>>
pub fn start_periodic_measurement(&mut self) -> Result<(), Error<E>>
Start periodic measurement mode. The default signal update interval is 5 seconds.
Sourcepub fn stop_periodic_measurement(&mut self) -> Result<(), Error<E>>
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.
Sourcepub fn start_low_power_periodic_measurement(&mut self) -> Result<(), Error<E>>
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.
Sourcepub fn data_ready(&mut self) -> Result<bool, Error<E>>
pub fn data_ready(&mut self) -> Result<bool, Error<E>>
Check if there is a measurement data ready to be read
Sourcepub fn read_measurement(&mut self) -> Result<Measurement, Error<E>>
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.
Sourcepub fn set_temperature_offset(&mut self, offset: f32) -> Result<(), Error<E>>
pub fn set_temperature_offset(&mut self, offset: f32) -> Result<(), Error<E>>
Configure the temperature offset
Sourcepub fn get_temperature_offset(&mut self) -> Result<f32, Error<E>>
pub fn get_temperature_offset(&mut self) -> Result<f32, Error<E>>
Retrieve the configured temperature offset
Sourcepub fn set_sensor_altitude(&mut self, altitude: u16) -> Result<(), Error<E>>
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.
Sourcepub fn get_sensor_altitude(&mut self) -> Result<u16, Error<E>>
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.
Sourcepub fn set_ambient_pressure(&mut self, pressure: u16) -> Result<(), Error<E>>
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.
Sourcepub fn get_ambient_pressure(&mut self) -> Result<u16, Error<E>>
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.
Sourcepub fn enable_automatic_self_calibration(
&mut self,
enabled: bool,
) -> Result<(), Error<E>>
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.
Sourcepub fn get_automatic_self_calibration(&mut self) -> Result<bool, Error<E>>
pub fn get_automatic_self_calibration(&mut self) -> Result<bool, Error<E>>
Check if the automatic self calibration algorithm is enabled
Sourcepub fn set_automatic_self_calibration_target(
&mut self,
ppm_co2: u16,
) -> Result<(), Error<E>>
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.
Sourcepub fn get_automatic_self_calibration_target(&mut self) -> Result<u16, Error<E>>
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.
Sourcepub fn perform_forced_recalibration(
&mut self,
ppm_co2: u16,
) -> Result<Option<i16>, Error<E>>
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
Sourcepub fn persists_settings(&mut self) -> Result<(), Error<E>>
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.
Sourcepub fn serial_number(&mut self) -> Result<u64, Error<E>>
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.
pub fn sensor_variant(&mut self) -> Result<Option<SensorVariant>, Error<E>>
Sourcepub fn perform_self_test(&mut self) -> Result<bool, Error<E>>
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.
Sourcepub fn perform_factory_reset(&mut self) -> Result<(), Error<E>>
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.
Sourcepub fn reinit(&mut self) -> Result<(), Error<E>>
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.
Sourcepub fn measure_single_shot(&mut self) -> Result<(), Error<E>>
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).
Sourcepub fn measure_single_shot_rht_only(&mut self) -> Result<(), Error<E>>
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.
Sourcepub fn power_down(&mut self) -> Result<(), Error<E>>
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.
Sourcepub fn wake_up(&mut self) -> Result<(), Error<E>>
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).