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:

class adafruit_as7331.AS7331(i2c_bus, address=_DEFAULT_ADDRESS)

Driver for the AS7331 UV Spectral Sensor.

Parameters:
  • i2c_bus (I2C) – The I2C bus the sensor is connected to

  • address (int) – The I2C address of the sensor. Defaults to 0x74.

property break_time: int

The break time for SYNS/SYND modes (0-255). Actual time = value * 8µs.

property clock_frequency: int

The internal clock frequency. Must be one of the CLOCK_* constants.

property data_ready: bool

Whether new measurement data is ready to read.

property device_id: int

The device part ID. Expected value is 0x21 for the AS7331.

property divider: int

The divider value (0-7). Division factor = 2^(1+value).

property divider_enabled: bool

Whether the result divider is enabled.

property edge_count: int

The edge count for SYND mode (0-255). 0 is treated as 1.

property gain: int

The sensor gain setting. Must be one of the GAIN_* constants, from GAIN_1X (lowest) to GAIN_2048X (highest).

property integration_time: int

The integration time setting. Must be one of the TIME_* constants, from TIME_1MS to TIME_16384MS.

property lost_data: bool

Whether data was lost (LDATA flag).

property measurement_mode: int

The measurement mode. Must be one of MODE_CONT, MODE_CMD, MODE_SYNS, or MODE_SYND.

property new_data: bool

Whether new data is available (NDATA flag).

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:

tuple

Raises:

RuntimeError – If the measurement times out.

property overflow: bool

Whether any overflow condition is present.

property power_down: bool

Whether the sensor is in power-down mode.

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:

tuple

Raises:

RuntimeError – If the measurement times out.

property ready_pin_open_drain: bool

The READY pin drive mode. True for open-drain, False for push-pull.

reset()

Perform a software reset, returning the sensor to configuration state.

property standby: bool

Whether standby mode is enabled.

start_measurement()

Start measurements by setting the SS bit.

property status: int

The status register byte (high byte of 16-bit OSR read).

stop_measurement()

Stop measurements by clearing the SS bit.

property temperature: float

The sensor temperature in degrees Celsius.

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.