Simple test¶
Ensure your device works with this simple test.
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
7import board
8import busio
9import adafruit_sgp30
10
11i2c = busio.I2C(board.SCL, board.SDA, frequency=100000)
12
13# Create library object on our I2C port
14sgp30 = adafruit_sgp30.Adafruit_SGP30(i2c)
15
16print("SGP30 serial #", [hex(i) for i in sgp30.serial])
17
18sgp30.iaq_init()
19sgp30.set_iaq_baseline(0x8973, 0x8AAE)
20sgp30.set_iaq_relative_humidity(celcius=22.1, relative_humidity=44)
21
22elapsed_sec = 0
23
24while True:
25 print("eCO2 = %d ppm \t TVOC = %d ppb" % (sgp30.eCO2, sgp30.TVOC))
26 time.sleep(1)
27 elapsed_sec += 1
28 if elapsed_sec > 10:
29 elapsed_sec = 0
30 print(
31 "**** Baseline values: eCO2 = 0x%x, TVOC = 0x%x"
32 % (sgp30.baseline_eCO2, sgp30.baseline_TVOC)
33 )