Loading...
Searching...
No Matches
SGP30 Gas Sensor

Device driver interface for the Sensirion SGP30 Gas Sensor. More...

Detailed Description

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).

Files

file  sgp30.h
 
file  sgp30_constants.h
 Internal addresses, registers and constants.
 
file  sgp30_params.h
 Default configuration.
 

Data Structures

struct  sgp30_data_t
 Set of measured values. More...
 
struct  sgp30_raw_data_t
 Set of measured raw values. More...
 
struct  sgp30_params_t
 Device initialization parameters. More...
 
struct  sgp30_t
 Device descriptor for the driver. More...
 

Functions

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)
 

Function Documentation

◆ sgp30_get_baseline()

int sgp30_get_baseline ( sgp30_t dev,
sgp30_data_t data 
)

Returns baseline values.

Parameters
[in]devDevice descriptor of the driver
[out]dataCurrent baseline values
Return values
0Success
-EBADMSGCRC checksum didn't match
-EPROTOSensor did not acknowledge command

◆ sgp30_init()

int sgp30_init ( sgp30_t dev,
const sgp30_params_t params 
)

Initialize the given device.

Parameters
[in,out]devDevice descriptor of the driver
[in]paramsInitialization 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]devDevice descriptor of the driver
[out]versionThe future set version
Return values
0Success
-EBADMSGCRC checksum didn't match
-EPROTOSensor did not acknowledge command

◆ sgp30_read_measurements()

int sgp30_read_measurements ( sgp30_t dev,
sgp30_data_t data 
)

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]devDevice descriptor of the driver
[out]dataAir quality measurements
Return values
0Success
-EAGAINSensor is not yet ready
-EBADMSGCRC checksum didn't match
-EPROTOSensor did not acknowledge command

◆ sgp30_read_raw_measurements()

int sgp30_read_raw_measurements ( sgp30_t dev,
sgp30_raw_data_t data 
)

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]devDevice descriptor of the driver
[out]dataRaw measurement values
Return values
0Success
-EBADMSGCRC checksum didn't match
-EPROTOSensor 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]devDevice descriptor of the driver
[out]bufPre-allocated memory for returning the serial number
[in]lenLength of the str buffer, must be 6
Return values
0Success
-EBADMSGCRC checksum didn't match
-EPROTOSensor did not acknowledge command

◆ sgp30_ready()

bool sgp30_ready ( sgp30_t dev)

If device is ready to start reading measurements.

Note
Only available if sgp30_strict is used
Parameters
[in]devDevice descriptor of the driver
Return values
trueIf ready to read measurements
falseIf still in warm-up period of it sgp30_start_air_quality has not been called

◆ sgp30_reset()

int sgp30_reset ( sgp30_t dev)

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]devDevice descriptor of the driver
Return values
0Success
-PROTOSensor 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]devDevice descriptor of the driver
[in]humidityHumidity in mg/m3 units. A values of 0 disables humidity compensation, max value is 255999 mg/m3.
Return values
0Success
-PROTOSensor did not acknowledge command

◆ sgp30_set_baseline()

int sgp30_set_baseline ( sgp30_t dev,
sgp30_data_t data 
)

Set new baseline values.

Parameters
[in]devDevice descriptor of the driver
[in]dataBaseline values to be set
Return values
0Success
-PROTOSensor 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]devDevice descriptor of the driver
Return values
0Success
-PROTOSensor did not acknowledge command