Simple test
Ensure your device works with this simple test.
examples/as7331_simpletest.py
1# SPDX-FileCopyrightText: Copyright (c) 2026 Liz Clark for Adafruit Industries
2#
3# SPDX-License-Identifier: MIT
4
5import time
6
7import board
8
9import adafruit_as7331
10
11i2c = board.I2C()
12sensor = adafruit_as7331.AS7331(i2c)
13
14# Optional: configure gain and integration time
15# sensor.gain = adafruit_as7331.GAIN_256X
16# sensor.integration_time = adafruit_as7331.TIME_64MS
17
18while True:
19 uva, uvb, uvc = sensor.one_shot()
20 print(f"UVA: {uva:.2f} UVB: {uvb:.2f} UVC: {uvc:.2f} µW/cm²")
21 print(f"Temperature: {sensor.temperature:.1f} °C")
22 print()
23 time.sleep(1)