Sgp41

Struct Sgp41 

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

Sgp41 driver instance

Create the driver instance with valid I²C address (0x59) and then it is just rock’n’roll. This driver doesn’t require special starting but once can start to make measurements right away. However, the initial values after start-up will unstable so you will want to throw away some of them.

Implementations§

Source§

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

Source

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

Creates Sgp41 driver

Source

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

Sensor self-test.

Performs sensor self-test. This is intended for production line and testing and verification only and shouldn’t be needed for normal use.

Source

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

Turn sensor heater off and places it in idle-mode.

Stops running the measurements, places heater into idle by turning the heaters off.

Source

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

Resets the sensor.

Executes a reset on the device. The caller must wait 100ms before starting to use the device again.

Source

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

Reads the voc index from the sensor.

Reads VOC index. Driver is using Sensirion gas index algorithm and it takes minimum 45 reads to start working. These reads should be made with 1Hz interval to keep the algorithm working.

Source

pub fn measure_voc_index_with_rht( &mut self, humidity: u16, temperature: i16, ) -> Result<u16, Error<E>>

Reads the voc index from the sensor with humidity and temperature compensation.

Reads VOC index with humidity and temperature compensation. Both values us milli-notation where 25°C is equivalent of 25000 and 50% humidity equals 50000.

Driver is using Sensirion gas index algorithm and it takes minimum 45 reads to start working. These reads should be made with 1Hz interval to keep the algorithm working.

Source

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

Reads the raw signal from the sensor.

Raw signal without temperature and humidity compensation. This is not VOC index but needs to be processed through different algorithm for that.

Source

pub fn measure_raw_with_rht( &mut self, humidity: u16, temperature: i16, ) -> Result<u16, Error<E>>

Reads the raw signal from the sensor.

Raw signal with temperature and humidity compensation. This is not VOC index but needs to be processed through different algorithm for that.

Note: For SGP41, this returns only the VOC raw signal for backward compatibility. Use measure_raw_signals_with_rht to get both VOC and NOx raw signals.

Source

pub fn measure_raw_signals_with_rht( &mut self, humidity: u16, temperature: i16, ) -> Result<(u16, u16), Error<E>>

Reads both VOC and NOx raw signals from the sensor.

Returns a tuple of (VOC raw signal, NOx raw signal) with temperature and humidity compensation. These are raw signals that need to be processed through algorithms for index calculation.

Source

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

Reads both VOC and NOx raw signals from the sensor with default compensation.

Returns a tuple of (VOC raw signal, NOx raw signal) using default humidity (50%) and temperature (25°C). These are raw signals that need to be processed through algorithms for index calculation.

Source

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

Reads the NOx raw signal from the sensor.

Raw NOx signal without temperature and humidity compensation. This is not NOx index but needs to be processed through different algorithm for that.

Source

pub fn measure_raw_nox_with_rht( &mut self, humidity: u16, temperature: i16, ) -> Result<u16, Error<E>>

Reads the NOx raw signal from the sensor with compensation.

Raw NOx signal with temperature and humidity compensation. This is not NOx index but needs to be processed through different algorithm for that.

Source

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

Reads the NOx index from the sensor.

Reads NOx index using default humidity (50%) and temperature (25°C). Driver is using Sensirion gas index algorithm and it takes minimum 45 reads to start working. These reads should be made with 1Hz interval to keep the algorithm working.

Source

pub fn measure_nox_index_with_rht( &mut self, humidity: u16, temperature: i16, ) -> Result<u16, Error<E>>

Reads the NOx index from the sensor with humidity and temperature compensation.

Reads NOx index with humidity and temperature compensation. Both values use milli-notation where 25°C is equivalent of 25000 and 50% humidity equals 50000.

Driver is using Sensirion gas index algorithm and it takes minimum 45 reads to start working. These reads should be made with 1Hz interval to keep the algorithm working.

Source

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

Reads both VOC and NOx indices from the sensor.

Returns a tuple of (VOC index, NOx index) using default humidity (50%) and temperature (25°C). Driver is using Sensirion gas index algorithm and it takes minimum 45 reads to start working. These reads should be made with 1Hz interval to keep the algorithm working.

Source

pub fn measure_indices_with_rht( &mut self, humidity: u16, temperature: i16, ) -> Result<(u16, u16), Error<E>>

Reads both VOC and NOx indices from the sensor with humidity and temperature compensation.

Returns a tuple of (VOC index, NOx index) with humidity and temperature compensation. Both values use milli-notation where 25°C is equivalent of 25000 and 50% humidity equals 50000.

Driver is using Sensirion gas index algorithm and it takes minimum 45 reads to start working. These reads should be made with 1Hz interval to keep the algorithm working.

Source

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

Sets the temperature offset.

This command sets the temperature offset used for the compensation of subsequent RHT measurements.RawSignals The parameter provides the temperature offset (in °C) with a scaling factor of 200, e.g., an output of +400 corresponds to +2.00 °C.

Source

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

Gets the temperature offset

Gets the temperature compensation offset issues to the device.

Source

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

Executes SGP41 conditioning sequence.

This command starts the conditioning, i.e., the VOC pixel will be operated at the same temperature as it is by calling the measure_raw_signals command while the NOx pixel will be operated at a different temperature for conditioning. This enables faster switch-on behavior thereafter.

It is recommended to execute the conditioning for 10 seconds, but 10 seconds must not be exceeded to avoid damage to the sensing material. This command returns the measured raw signal of the VOC pixel (SRAW_VOC) during conditioning.

This method should be called after each restart of the sensor or when the hotplates have been switched off, before the first measure_raw_signals command.

Source

pub fn execute_conditioning_with_rht( &mut self, humidity: u16, temperature: i16, ) -> Result<u16, Error<E>>

Executes SGP41 conditioning sequence with custom humidity and temperature.

This command starts the conditioning with specified humidity and temperature compensation. Both values use milli-notation where 25°C is equivalent of 25000 and 50% humidity equals 50000.

Returns the measured raw signal of the VOC pixel (SRAW_VOC) during conditioning.

Source

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

Executes SGP41 conditioning sequence with VOC reading.

This is an alias for execute_conditioning() since the conditioning command already returns the VOC raw signal. This method is provided for API completeness and clarity.

Returns the measured raw signal of the VOC pixel (SRAW_VOC) during conditioning.

Source

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

Acquires the sensor serial number.

Sensor serial number is only 48-bits long so the remaining 16-bits are zeros.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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