Expand description
Sensirion SCD40 and SCD41 CO2, temperature, and humidity sensor.
The SCD4x is a photoacoustic NDIR CO2 sensor with a built-in humidity and temperature sensor, driven over I2C by 16-bit command words. Every data word it sends or receives is followed by a CRC-8, and its measurement is three such words: CO2 in parts per million, then a temperature and a humidity ratio scaled over the 16-bit range. This module carries the command table, the checksum, the frame builders and parsers, and the datasheet’s conversion formulas, each anchored to the worked examples the datasheet prints beside its command descriptions.
A caller sends command::START_PERIODIC_MEASUREMENT once, polls
data_ready on the command::GET_DATA_READY_STATUS word, and reads the nine
bytes of command::READ_MEASUREMENT into Measurement::parse. Temperatures
and humidities are returned in integer milli-units, with f32 conveniences
beside them.
Modules§
- command
- The command words (Table 9), 16 bits each, most significant byte first, with no CRC after the command itself.
Structs§
- Measurement
- One SCD4x measurement, as the three words of
read_measurement.
Constants§
- CO2_
MAX_ PPM - The largest CO2 concentration the sensor reports, in ppm (Table 1: output range 0 to 40’000 ppm).
- DEFAULT_
TEMPERATURE_ OFFSET_ MILLI_ CELSIUS - The factory temperature offset, in milli-degrees Celsius (section 3.6.1: “per default, the temperature offset is set to 4 °C”).
- FORCED_
RECALIBRATION_ FAILED - The
perform_forced_recalibrationresponse that reports a failed recalibration (Table 18). - I2C_
ADDRESS - The I2C address (Table 8); the part has no address pins.
- LOW_
POWER_ PERIODIC_ MEASUREMENT_ INTERVAL_ MS - The approximate signal update interval of low power periodic measurement, in milliseconds (section 3.8).
- PERIODIC_
MEASUREMENT_ INTERVAL_ MS - The signal update interval of periodic measurement, in milliseconds (section 3.5).
- POWER_
UP_ TIME_ MS - The time the sensor needs after power-up or
reinitbefore it accepts a command, in milliseconds (Table 7).
Functions§
- allowed_
during_ measurement - Returns whether a command may be sent while a periodic measurement is running.
- ambient_
pressure_ pascals - Decodes an ambient pressure word back to pascals.
- ambient_
pressure_ word - Encodes an ambient pressure as the
set_ambient_pressureword. - automatic_
self_ calibration_ enabled - Returns whether an automatic self-calibration word reports ASC enabled.
- automatic_
self_ calibration_ word - Builds the automatic self-calibration word for an enabled state.
- celsius
- Decodes the raw temperature word to degrees Celsius.
- command_
frame - Builds the two bytes of a command that carries no data word.
- crc
- Computes the CRC-8 that follows every data word.
- data_
ready - Returns whether the data ready word reports a measurement waiting to be read.
- forced_
recalibration_ correction_ ppm - Decodes the
perform_forced_recalibrationresponse to the correction applied. - forced_
recalibration_ word - Builds the
perform_forced_recalibrationresponse word for a correction. - humidity_
milli_ percent - Decodes the raw humidity word to thousandths of a percent relative humidity.
- humidity_
raw - Builds the raw humidity word the sensor reports for a relative humidity.
- max_
duration_ ms - Returns the maximum command duration of a command word, in milliseconds.
- milli_
celsius - Decodes the raw temperature word to milli-degrees Celsius.
- relative_
humidity_ percent - Decodes the raw humidity word to percent relative humidity.
- self_
test_ passed - Returns whether the self-test word reports no malfunction.
- serial_
number - Decodes the nine bytes of
get_serial_numberto the 48-bit serial number. - serial_
number_ frame - Builds the nine bytes a sensor sends for a serial number.
- temperature_
offset_ milli_ celsius - Decodes the
get_temperature_offsetword to milli-degrees Celsius. - temperature_
offset_ word - Encodes a temperature offset as the
set_temperature_offsetword. - temperature_
raw - Builds the raw temperature word the sensor reports for a temperature.
- word
- Decodes one data word from its three-byte frame, checking the CRC.
- word_
frame - Builds the three-byte frame of one data word: the word, most significant byte first, followed by its CRC.
- write_
frame - Builds the five bytes of a write command: the command word followed by one data word and its CRC.