snsary.contrib.adafruit.sgp30
Wrapper for the Adafruit SGP30 sensor, inheriting from GenericSensor:
Waits 15 seconds for the device to warm up (as per the datasheet).
Standardises the name used for logs and readings to “SGP30”.
The installation and configuration is the same as the generic wrapper:
# install the sensor library
pip3 install adafruit-circuitpython-sgp30
# create the sensor object
import board
i2c = board.I2C()
sgp30 = adafruit_sgp30.Adafruit_SGP30(i2c)
# prepare to poll / scrape
SGP30Sensor(sgp30)
SGP30Sensor polls at the default period of GenericSensor. The datasheet says it should be 1s, but this doesn’t work in practice, especially when the I2C bus is busy.
Humidity compensation
SGP30Sensor is also an Output. The TVOC and eCO2 readings from the SGP30 sensor need to be adjusted based on the absolute humidity of the surrounding air, which can be calculated from the “temperature” and “relative_humidity” in a batch of Readings:
# SCD30 outputs the required readings
GenericSensor(scd30).stream.tee(sgp30)
The required names - “tempeature” and “relative_humidity” - may not match some sensors. One way to work around this is to rename each Reading on the fly:
OtherSensor.stream.filter_names('temp').rename(to='temperature').into(sgp30)
OtherSensor.stream.filter_names('humid').rename(to='relative_humidity').into(sgp30)
Persistent IAQ baselines
SGP30Sensor emits baseline_TVOC and baseline_eCO2 values, which are a moving average of the best environmental conditions the sensor has encountered. Higher values are better (from manual observation). Adafruit recommend exposing the sensor to fresh air for at least 10 minutes as part of configuring the IAQ baseline.
Every time the SGP30 sensor is sampled, the values of both baseline Readings are checked. Higher values are set as the new baseline for future readings; use persistent_baselines=False in the constructor to disable this. The baseline values are kept in persistent storage so they survive restarts. See the storage module for more details.