Reference
SGP30
Air quality: TVOC (ppb) and equivalent CO2 (ppm), with humidity compensation and baseline save/restore.
- Connects over
- I²C
- Address
- 0x58
- Made by
- Sensirion
- Datasheet
- sensirion.com
Use it
hardware {
device sgp30: SGP30
}
every 1s {
let value: int = sgp30.baseline_eco2()
log("sgp30", "baseline_eco2={value}")
}
On its own, the declaration puts the SGP30 on the first I²C bus (SDA 21, SCL 22 on the ESP32) at 0x58. To choose the pins or the address, declare the bus and attach the device: device sgp30: SGP30 on i2c0 at 0x58 with i2c i2c0(sda: 21, scl: 22).
Methods
-
sgp30.baseline_eco2() -> int
Current eCO2 baseline, to save to storage.
-
sgp30.baseline_tvoc() -> int
Current TVOC baseline, to save to storage.
-
sgp30.eco2() -> int
Equivalent CO2 in ppm (400-60000).
-
sgp30.ready() -> bool
False during the 15 s warm-up after init, or if the last read failed.
-
sgp30.set_baseline(eco2: int, tvoc: int)
Restore baselines saved earlier (call in setup, after a fresh boot).
-
sgp30.set_humidity(temp_c: float, rh: float)
Humidity compensation from air temperature (°C) and relative humidity (%), e.g. from an SHT31 or BME280. Call whenever they change.
-
sgp30.tvoc() -> int
Total volatile organic compounds in ppb (0-60000).
Wiring
| Pin | Connect to |
|---|---|
VIN | 3.3V or 5V on breakouts with a regulator |
GND | Ground |
SDA | I2C data, pull-up on most breakouts |
SCL | I2C clock |
Specifications
- Current
- 48 mA while measuring
- Eco2
- 400 - 60000 ppm
- Sample rate
- 1 Hz (the on-chip algorithm expects it)
- Tvoc
- 0 - 60000 ppb
- Voltage
- 1.62V - 1.98V die (breakouts regulate 3.3V/5V)
Tips
- Read it once per second: the baseline algorithm depends on a steady 1 Hz rate. The driver measures at most once per second however often you call it.
- For the first 15 s after power-up it reports 400 ppm eCO2 and 0 ppb TVOC (warming up); ready() is false until then.
- Save baseline_eco2()/baseline_tvoc() to storage about once an hour and restore them with set_baseline() at boot; a stored baseline older than 7 days should be discarded.
- eCO2 is estimated from hydrogen, not measured; use an SCD4x for true CO2.
Alternatives worth knowing:
- ENS160: Adds an AQI 1-5 index; similar TVOC/eCO2 estimates.
- SCD4x: True NDIR CO2 in ppm.