Device driver interface for the Sensirion SGP30 Gas Sensor.
More...
Device driver interface for the Sensirion SGP30 Gas Sensor.
About
This driver provides an interface for the Sensirion SGP30 Gas Sensor. The Datasheet can be found here
After the sensor is powered up and starts measuring air quality for the first 15s sgp30_read_measurements calls will return fixed values of of 400ppm CO2eq and 0ppb TVOC. Afterwards values should be read in regular intervals of 1s for best operation of the dynamic baseline compensation algorithm.
The above is not done by default unless the sgp30_strict
module is included. In that case, if attempting to read before the is completed, then -EAGAIN will be returned. After this periodic readings happen every 1s, and the last value read is returned when calling sgp30_read_measurements. A timestamp is also added to sgp30_data_t.
The sensor features on-chip humidity compensation for the air quality measurements. sgp30_set_absolute_humidity can be used to change the absolute humidity value used. See [SGP30 driver integration] (https://files.seeedstudio.com/wiki/Grove-VOC_and_eCO2_Gas_Sensor-SGP30/res/Sensirion_Gas_Sensors_SGP30_Driver-Integration-Guide_HW_I2C.pdf) for more on this. The baseline values for the correction algorithm can also be tweaked with sgp30_set_baseline. More on how to implement dynamic baseline compensation can be seen at [SGP30 driver integration] (https://files.seeedstudio.com/wiki/Grove-VOC_and_eCO2_Gas_Sensor-SGP30/res/Sensirion_Gas_Sensors_SGP30_Driver-Integration-Guide_HW_I2C.pdf).
|
int | sgp30_init (sgp30_t *dev, const sgp30_params_t *params) |
| Initialize the given device.
|
|
int | sgp30_start_air_quality (sgp30_t *dev) |
| Start air quality measurements, called on sgp30_init.
|
|
int | sgp30_read_future_set (sgp30_t *dev, uint16_t *version) |
| Initialize the given device.
|
|
int | sgp30_reset (sgp30_t *dev) |
| Performs a soft reset on the device.
|
|
bool | sgp30_ready (sgp30_t *dev) |
| If device is ready to start reading measurements.
|
|
int | sgp30_read_serial_number (sgp30_t *dev, uint8_t *buf, size_t len) |
| Read the serial number from the sensor.
|
|
int | sgp30_read_measurements (sgp30_t *dev, sgp30_data_t *data) |
| Read air quality signals.
|
|
int | sgp30_set_absolute_humidity (sgp30_t *dev, uint32_t humidity) |
| Set absolute humidity value for on-chop humidity compensation.
|
|
int | sgp30_set_baseline (sgp30_t *dev, sgp30_data_t *data) |
| Set new baseline values.
|
|
int | sgp30_get_baseline (sgp30_t *dev, sgp30_data_t *data) |
| Returns baseline values.
|
|
int | sgp30_read_raw_measurements (sgp30_t *dev, sgp30_raw_data_t *data) |
| Read raw signals H2 (sout_H2) and Ethanol(sout_EthOH)
|
|
◆ sgp30_get_baseline()
Returns baseline values.
- Parameters
-
[in] | dev | Device descriptor of the driver |
[out] | data | Current baseline values |
- Return values
-
0 | Success |
-EBADMSG | CRC checksum didn't match |
-EPROTO | Sensor did not acknowledge command |
◆ sgp30_init()
Initialize the given device.
- Parameters
-
[in,out] | dev | Device descriptor of the driver |
[in] | params | Initialization parameters |
- Returns
- 0 on success
◆ sgp30_read_future_set()
int sgp30_read_future_set |
( |
sgp30_t * |
dev, |
|
|
uint16_t * |
version |
|
) |
| |
Initialize the given device.
- Parameters
-
[in] | dev | Device descriptor of the driver |
[out] | version | The future set version |
- Return values
-
0 | Success |
-EBADMSG | CRC checksum didn't match |
-EPROTO | Sensor did not acknowledge command |
◆ sgp30_read_measurements()
Read air quality signals.
- Note
- For the first 15s after the “Init_air_quality” command (called in the init function) the sensor is in an initialization phase during which a “Measure_air_quality” command returns fixed values of 400ppm CO2eq and 0ppb TVOC.
- Parameters
-
[in] | dev | Device descriptor of the driver |
[out] | data | Air quality measurements |
- Return values
-
0 | Success |
-EAGAIN | Sensor is not yet ready |
-EBADMSG | CRC checksum didn't match |
-EPROTO | Sensor did not acknowledge command |
◆ sgp30_read_raw_measurements()
Read raw signals H2 (sout_H2) and Ethanol(sout_EthOH)
It returns the sensor raw sensor signals which are used as inputs for the on-chip calibration and baseline compensation algorithms.
- Parameters
-
[in] | dev | Device descriptor of the driver |
[out] | data | Raw measurement values |
- Return values
-
0 | Success |
-EBADMSG | CRC checksum didn't match |
-EPROTO | Sensor did not acknowledge command |
◆ sgp30_read_serial_number()
int sgp30_read_serial_number |
( |
sgp30_t * |
dev, |
|
|
uint8_t * |
buf, |
|
|
size_t |
len |
|
) |
| |
Read the serial number from the sensor.
- Parameters
-
[in] | dev | Device descriptor of the driver |
[out] | buf | Pre-allocated memory for returning the serial number |
[in] | len | Length of the str buffer, must be 6 |
- Return values
-
0 | Success |
-EBADMSG | CRC checksum didn't match |
-EPROTO | Sensor did not acknowledge command |
◆ sgp30_ready()
If device is ready to start reading measurements.
- Note
- Only available if sgp30_strict is used
- Parameters
-
[in] | dev | Device descriptor of the driver |
- Return values
-
true | If ready to read measurements |
false | If still in warm-up period of it sgp30_start_air_quality has not been called |
◆ sgp30_reset()
Performs a soft reset on the device.
- Warning
- Reset is performed via a "General Call". All devices on the same I2C bus that support the General Call mode will perform a reset.
- Parameters
-
[in] | dev | Device descriptor of the driver |
- Return values
-
0 | Success |
-PROTO | Sensor did not acknowledge command |
◆ sgp30_set_absolute_humidity()
int sgp30_set_absolute_humidity |
( |
sgp30_t * |
dev, |
|
|
uint32_t |
humidity |
|
) |
| |
Set absolute humidity value for on-chop humidity compensation.
- Note
- This function requires absolute humidity values, most sensors output relative humidity, this can be calculated if temperature is also known:
AH = 216.7 * ((RH / 100.0) * 6.112 * exp(17.62 * T / (243.12 + T))) / (273.15 + T)
Where RH is in 0-100%, and T is in C.
(*) Approximation formula from Sensirion SGP30 Driver Integration chapter 3.15
- Parameters
-
[in] | dev | Device descriptor of the driver |
[in] | humidity | Humidity in mg/m3 units. A values of 0 disables humidity compensation, max value is 255999 mg/m3. |
- Return values
-
0 | Success |
-PROTO | Sensor did not acknowledge command |
◆ sgp30_set_baseline()
Set new baseline values.
- Parameters
-
[in] | dev | Device descriptor of the driver |
[in] | data | Baseline values to be set |
- Return values
-
0 | Success |
-PROTO | Sensor did not acknowledge command |
◆ sgp30_start_air_quality()
int sgp30_start_air_quality |
( |
sgp30_t * |
dev | ) |
|
Start air quality measurements, called on sgp30_init.
- Note
- Must be called after every power-cycle or soft reset.
- Parameters
-
[in,out] | dev | Device descriptor of the driver |
- Return values
-
0 | Success |
-PROTO | Sensor did not acknowledge command |