Simple test

Ensure your device works with this simple test.

examples/ags02ma_simpletest.py
 1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
 2# SPDX-FileCopyrightText: Copyright (c) 2022 ladyada for Adafruit Industries
 3#
 4# SPDX-License-Identifier: Unlicense
 5
 6import time
 7import board
 8import busio
 9from adafruit_ags02ma import AGS02MA
10
11# MUST connect I2C at 20KHz! Note some processors, like SAMD21 and SAMD51
12# do not go that low...but RP2040, ESP32-S2 does
13i2c = busio.I2C(board.SCL, board.SDA, frequency=20_000)
14
15ags = AGS02MA(i2c, address=0x1A)
16
17# It is possible to change the I2C address 'semi-permanently' but
18# note that you'll need to restart the script after adjusting the address!
19# ags.set_address(0x1A)
20
21while True:
22    try:
23        res = ags.gas_resistance
24        print("Gas resistance: %0.1f Kohms" % (res / 1000))
25        tvoc = ags.TVOC
26        print("TVOC: %d ppb" % tvoc)
27    except RuntimeError:
28        print("Retrying....")
29    time.sleep(1)