typedef enum {
SUCCESS = 0,
ERR_BAD_CRC,
ERR_I2C_TIMEOUT,
SELF_TEST_FAIL
} SGP30ERR;
This enum allows us to simply tell what error code was returned by its description instead of getting a number for
an error which you would then have to "decode". For example, instead of returning
returns
error == SUCCESS
Device Setup & Settings
bool begin(TwoWire &wirePort);
void initAirQuality(void);
calling
measureAirQuality
void generalCallReset(void);
reset any attached device that support the General Call Mode.
getFeatureSetVersion(void);
the datasheet for more information.
getSerialID(void);
connected.
measureTest(void);
for testing.
Measurement Functions
measureAirQuality(void);
intervals to maintain baseline calculations.
setBaseline(void);
previously retrieved baselines to maintain accuracy.
getBaseline(void);
calculations.
setHumidity(uint16_t humidity);
modified, the new humidity value should be taken from a humidity sensor like the SHTC3. Sending
resets to default and turns off humidity compensation. Refer to "Example3_Humidity" in our Arduino library
for more information on calculating and sending this value.
measureRawSignals(void);
on-chip calibration and baseline compensation algorithms. Refer to page 8 of the datasheet for more
information.
With the core functions of this Arduino library outlined and explained, it's time to start putting them together in
some example code.
Arduino Examples
The SGP30 Arduino Library includes nine examples to get you started. For the scope of this tutorial, we'll just
cover the first three as they demonstrate the basics of setting up and reading from the SGP30.
Example 1 - Basic Readings
. Now, on to the rest of the functions.
- Initializes the sensor on the I C bus and selects the wire port.
- Initializes air quality measurements on the SGP30. Must be called prior to
.
- Performs a soft reset of the SGP30. Not device specific and this call can
- Returns a readout of the feature set version number. Refer to page 8 of
- Returns a readout of the serial ID register to identify the chip and verify the sensor is
- Runs a self test on the SGP30. This function is primarily used by the manufacturer
- Returns CO values in ppm and TVOC values in ppb. Call in regular 1 second
2
- Updates the baseline values to a previous baseline. Recommended to only use
- Returns the current calculated baseline from the SGP30's dynamic baseline
- Set a humidity value for compensation. Default is 15.5g/m and if
- Returns raw signals for H and ethanol. These values are used as inputs for
error == 0
2
2
an error check
3
0x0000
Need help?
Do you have a question about the SGP30 and is the answer not in the manual?