API Reference
adafruit_as7331
CircuitPython driver for the Adafruit AS7331 UV / UVA / UVB / UVC Sensor Breakout
Author(s): Liz Clark
Implementation Notes
Hardware:
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://circuitpython.org/downloads
Adafruit’s Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
Adafruit’s Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
- class adafruit_as7331.AS7331(i2c_bus, address=_DEFAULT_ADDRESS)
Driver for the AS7331 UV Spectral Sensor.
- Parameters:
- property gain: int
The sensor gain setting. Must be one of the
GAIN_*constants, fromGAIN_1X(lowest) toGAIN_2048X(highest).
- property integration_time: int
The integration time setting. Must be one of the
TIME_*constants, fromTIME_1MStoTIME_16384MS.
- property measurement_mode: int
The measurement mode. Must be one of
MODE_CONT,MODE_CMD,MODE_SYNS, orMODE_SYND.
- one_shot() Tuple[float, float, float]
Perform a single measurement in command mode and return irradiance.
Configures the sensor for CMD mode, triggers a measurement, waits for completion, and converts results to µW/cm².
- Returns:
Tuple of (uva, uvb, uvc) irradiance in µW/cm².
- Return type:
- Raises:
RuntimeError – If the measurement times out.
- raw_one_shot() Tuple[float, float, float]
Perform a single measurement in command mode and return raw counts.
Configures the sensor for CMD mode, triggers a measurement, waits for completion, and returns raw ADC counts.
- Returns:
Tuple of (uva, uvb, uvc) raw ADC counts.
- Return type:
- Raises:
RuntimeError – If the measurement times out.
- property ready_pin_open_drain: bool
The READY pin drive mode.
Truefor open-drain,Falsefor push-pull.
- reset()
Perform a software reset, returning the sensor to configuration state.
- start_measurement()
Start measurements by setting the SS bit.
- stop_measurement()
Stop measurements by clearing the SS bit.
- adafruit_as7331.CLOCK_1024KHZ = 0
1.024 MHz clock.
- adafruit_as7331.CLOCK_2048KHZ = 1
2.048 MHz clock.
- adafruit_as7331.CLOCK_4096KHZ = 2
4.096 MHz clock.
- adafruit_as7331.CLOCK_8192KHZ = 3
8.192 MHz clock.
- adafruit_as7331.GAIN_1024X = 1
1024x gain.
- adafruit_as7331.GAIN_128X = 4
128x gain.
- adafruit_as7331.GAIN_16X = 7
16x gain.
- adafruit_as7331.GAIN_1X = 11
1x gain (lowest sensitivity).
- adafruit_as7331.GAIN_2048X = 0
2048x gain (highest sensitivity).
- adafruit_as7331.GAIN_256X = 3
256x gain.
- adafruit_as7331.GAIN_2X = 10
2x gain.
- adafruit_as7331.GAIN_32X = 6
32x gain.
- adafruit_as7331.GAIN_4X = 9
4x gain.
- adafruit_as7331.GAIN_512X = 2
512x gain.
- adafruit_as7331.GAIN_64X = 5
64x gain.
- adafruit_as7331.GAIN_8X = 8
8x gain.
- adafruit_as7331.MODE_CMD = 1
Command mode (single measurement).
- adafruit_as7331.MODE_CONT = 0
Continuous measurement mode.
- adafruit_as7331.MODE_SYND = 3
Synchronized data mode.
- adafruit_as7331.MODE_SYNS = 2
Synchronized start mode.
- adafruit_as7331.TIME_1024MS = 10
1024 ms integration time.
- adafruit_as7331.TIME_128MS = 7
128 ms integration time.
- adafruit_as7331.TIME_16384MS = 14
16384 ms integration time.
- adafruit_as7331.TIME_16MS = 4
16 ms integration time.
- adafruit_as7331.TIME_1MS = 0
1 ms integration time.
- adafruit_as7331.TIME_2048MS = 11
2048 ms integration time.
- adafruit_as7331.TIME_256MS = 8
256 ms integration time.
- adafruit_as7331.TIME_2MS = 1
2 ms integration time.
- adafruit_as7331.TIME_32MS = 5
32 ms integration time.
- adafruit_as7331.TIME_4096MS = 12
4096 ms integration time.
- adafruit_as7331.TIME_4MS = 2
4 ms integration time.
- adafruit_as7331.TIME_512MS = 9
512 ms integration time.
- adafruit_as7331.TIME_64MS = 6
64 ms integration time.
- adafruit_as7331.TIME_8192MS = 13
8192 ms integration time.
- adafruit_as7331.TIME_8MS = 3
8 ms integration time.