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
7
8import board
9import busio
10
11from adafruit_ags02ma import AGS02MA
12
13# MUST connect I2C at 20KHz! Note some processors, like SAMD21 and SAMD51
14# do not go that low...but RP2040, ESP32-S2 does
15i2c = busio.I2C(board.SCL, board.SDA, frequency=20_000)
16
17ags = AGS02MA(i2c, address=0x1A)
18
19# It is possible to change the I2C address 'semi-permanently' but
20# note that you'll need to restart the script after adjusting the address!
21# ags.set_address(0x1A)
22
23while True:
24 try:
25 res = ags.gas_resistance
26 print("Gas resistance: %0.1f Kohms" % (res / 1000))
27 tvoc = ags.TVOC
28 print(f"TVOC: {tvoc:d} ppb")
29 except RuntimeError:
30 print("Retrying....")
31 time.sleep(1)