Simple test
Ensure your device works with this simple test.
examples/sgp30_simpletest.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4"""Example for using the SGP30 with CircuitPython and the Adafruit library"""
5
6import time
7
8import board
9import busio
10
11import adafruit_sgp30
12
13i2c = busio.I2C(board.SCL, board.SDA, frequency=100000)
14
15# Create library object on our I2C port
16sgp30 = adafruit_sgp30.Adafruit_SGP30(i2c)
17
18print("SGP30 serial #", [hex(i) for i in sgp30.serial])
19
20sgp30.set_iaq_baseline(0x8973, 0x8AAE)
21sgp30.set_iaq_relative_humidity(celsius=22.1, relative_humidity=44)
22
23elapsed_sec = 0
24
25while True:
26 print(f"eCO2 = {sgp30.eCO2} ppm \t TVOC = {sgp30.TVOC} ppb")
27 time.sleep(1)
28 elapsed_sec += 1
29 if elapsed_sec > 10:
30 elapsed_sec = 0
31 print(
32 f"**** Baseline values: eCO2 = 0x{sgp30.baseline_eCO2:x}, TVOC = 0x{sgp30.baseline_TVOC:x}" # noqa: E501
33 )