adafruit_sgp40

CircuitPython library for the Adafruit SGP40 Air Quality Sensor / VOC Index Sensor Breakouts

  • Author(s): Bryan Siepert

    Keith Murray

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_sgp40.SGP40(i2c, address=89)

Class to use the SGP40 Air Quality Sensor Breakout

Parameters

address (int) – The I2C address of the device. Defaults to 0x59

Quickstart: Importing and using the SGP40 temperature sensor

Here is one way of importing the SGP40 class 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.I2C object 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)

Now you have access to the raw gas value using the raw attribute. And with a temperature and humidity value, you can access the class function measure_raw() for a humidity compensated raw reading

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)

Note

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

initialize()

Reset the sensor to it’s initial unconfigured state and configure it with sensible defaults so it can be used

measure_index(temperature=25, relative_humidity=50)

Measure VOC index after humidity compensation :param float temperature: The temperature in degrees Celsius, defaults to 25 :param float relative_humidity: The relative humidity in percentage, defaults to 50 :note VOC index can indicate the quality of the air directly. The larger the value, the worse the air quality. :note 0-100, no need to ventilate, purify :note 100-200, no need to ventilate, purify :note 200-400, ventilate, purify :note 00-500, ventilate, purify intensely :return int The VOC index measured, ranged from 0 to 500

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.

Parameters
  • temperature (float) – The temperature in degrees Celsius, defaults to 25

  • relative_humidity (float) – The relative humidity in percentage, defaults to 50

The raw gas value adjusted for the current temperature (c) and humidity (%)

property raw

The raw gas value