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
 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.set_iaq_baseline(0x8973, 0x8AAE)
19sgp30.set_iaq_relative_humidity(celsius=22.1, relative_humidity=44)
20
21elapsed_sec = 0
22
23while True:
24    print("eCO2 = %d ppm \t TVOC = %d ppb" % (sgp30.eCO2, sgp30.TVOC))
25    time.sleep(1)
26    elapsed_sec += 1
27    if elapsed_sec > 10:
28        elapsed_sec = 0
29        print(
30            "**** Baseline values: eCO2 = 0x%x, TVOC = 0x%x"
31            % (sgp30.baseline_eCO2, sgp30.baseline_TVOC)
32        )