Air Quality Sensor - SGP40 (Qwiic) Hookup Guide
SGP40 Arduino Library
We've written a simple Arduino library to quickly get started reading data from the SGP40. Install the library through the Arduino Library Manager tool by searching for "SparkFun SGP40". Users who prefer to manually install it can get the library from the GitHub Repository or download the ZIP by clicking the button below:
The list below outlines all of the functions of the library with some quick descriptions of what they do.
SGP40 object in the global scope.
mySensor is used as the SGP40 object in the example.
Device Setup and Settings
bool SGP40::begin(TwoWire &wirePort);- Initialize I2C communication with the SGP40 on the defined port. If no port is specified, Wire is used. This function also initializes the VOC index parameters.
void enableDebugging(Stream &debugPort = Serial);- Turn debug printouts and select the Serial port used for prints. If no port is defined, Serial is used.
SGP40ERR measureTest(void);- Run a self test of the SGP40 chip. Returns
SUCCESS (0)on pass or specific error code on fail when debugging prints are enabled. Primarily used during manufacturing but can be helpful for debugging.
SGP40ERR softReset(void);- Trigger a soft reset of the SGP40. Returns
SUCCESS (0)if reset is successful with debugging enabled.
SGP40ERR heaterOff(void);- Turn the heater off. Returns
SUCCESS (0)if heater is successfully disabled with debugging enabled.
SGP40 VOC Data
Both of these data outputs have default values set for relative humidity percentage and temperature (in °C) that can be adjusted to new static values or fed a live humidity and temperature data from an external sensor.
SGP40ERR measureRaw(uint16_t *SRAW_ticks, float RH = 50, float T = 25);- Returns the raw signal from the SGP40 in
SRAW_ticks. If debugging statements are on, returns
SUCCESS (0)on pass.
int32_t getVOCindex(float RH = 50, float T = 25);- Return the processed VOC index data from the SGP40. Returns
-100on error. Refer to the VOC Index app note document for more information on the Sensirion VOC Index.