CircuitPython library for the Adafruit SGP40 Air Quality Sensor / VOC Index Sensor Breakouts
- Author(s): Bryan Siepert
Adafruit SGP40 Air Quality Sensor Breakout - VOC Index <https://www.adafruit.com/product/4829>
In order to use the
measure_rawfunction, a temperature and humidity sensor which updates at at least 1Hz is needed (BME280, BME688, SHT31-D, SHT40, etc. For more, see: https://www.adafruit.com/category/66)
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://github.com/adafruit/circuitpython/releases
Adafruit’s Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
- class adafruit_sgp40.SGP40(i2c, address=89)¶
Class to use the SGP40 Air Quality Sensor Breakout
address (int) – The I2C address of the device. Defaults to
Quickstart: Importing and using the SGP40 temperature sensor
Here is one way of importing the
SGP40class so you can use it with the name
sgp. First you will need to import the libraries to use the sensor
import board import adafruit_sgp40 # If you have a temperature sensor, like the bme280, import that here as well # import adafruit_bme280
Once this is done you can define your
board.I2Cobject and define your sensor object
i2c = board.I2C() # uses board.SCL and board.SDA sgp = adafruit_sgp40.SGP40(i2c) # And if you have a temp/humidity sensor, define the sensor here as well # bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)
raw_gas_value = sgp.raw # Lets quickly grab the humidity and temperature # temperature = bme280.temperature # humidity = bme280.relative_humidity # compensated_raw_gas = sgp.measure_raw(temperature=temperature, # relative_humidity=humidity) # temperature = temperature, relative_humidity = humidity)
The operational range of temperatures for the SGP40 is -10 to 50 degrees Celsius and the operational range of relative humidity for the SGP40 is 0 to 90 % (assuming that humidity is non-condensing).
Humidity compensation is further optimized for a subset of the temperature and relative humidity readings. See Figure 3 of the Sensirion datasheet for the SGP40. At 25 degrees Celsius, the optimal range for relative humidity is 8% to 90%. At 50% relative humidity, the optimal range for temperature is -7 to 42 degrees Celsius.
Prolonged exposures outside of these ranges may reduce sensor performance, and the sensor must not be exposed towards condensing conditions at any time.
For more information see: https://www.sensirion.com/fileadmin/user_upload/customers/sensirion/Dokumente/9_Gas_Sensors/Datasheets/Sensirion_Gas_Sensors_Datasheet_SGP40.pdf and https://learn.adafruit.com/adafruit-sgp40
Reset the sensor to it’s initial unconfigured state and configure it with sensible defaults so it can be used
- measure_raw(temperature=25, relative_humidity=50)¶
A humidity and temperature compensated raw gas value which helps address fluctuations in readings due to changing humidity.
The raw gas value adjusted for the current temperature (c) and humidity (%)
- property raw¶
The raw gas value