API Reference
adafruit_as7343
CircuitPython driver for the ams OSRAM AS7343 14-channel spectral sensor.
Author(s): Tim Cocks
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_as7343.AS7343(i2c_bus: I2C, address: int = _AS7343_I2C_ADDRESS)
CircuitPython driver for the ams OSRAM AS7343 14-channel spectral sensor.
- Parameters:
Quickstart: Importing and using the device
import board from adafruit_as7343 import AS7343 i2c = board.I2C() sensor = AS7343(i2c) readings = sensor.all_channels
Note
The AS7343 has two register banks selected by bit 4 of CFG0 (0xBF):
Bank 0 (default,
REG_BANK=0): registers at 0x80 and above.Bank 1 (
REG_BANK=1): registers at 0x58–0x7F (ID, REVID, AUXID, GPIO, CFG10, CFG12).
CFG0 itself is always accessible in both bank modes and is used to switch between them via
_set_bank().- property all_channels: List[int]
Trigger a measurement and return all channel readings.
Starts a single measurement, waits for AVALID (fires after all auto-SMUX cycles complete), then returns a list of 16-bit readings. The list length matches the current
smux_mode: 6, 12, or 18 values.Uses
read_timeoutas the maximum number of milliseconds to wait for data ready.- Returns:
List of channel counts in the order defined by
Channel.- Raises:
TimeoutError – If data is not ready within
read_timeoutms.
- property astep: int
Integration step size (ASTEP), 0–65534.
Integration time (ms) = (
atime+ 1) × (astep+ 1) × 2.78 µs. 65535 is reserved by hardware.
- property auto_zero_frequency: int
Cycles between automatic zero-offset calibration runs (0–255).
0— auto-zero disabled (not recommended)1— every measurement cycle255— only before the very first measurement (default)
- property flicker_frequency: int
Detected mains flicker frequency.
Returns a
FlickerFreqvalue:FlickerFreq.NONE— no flicker detectedFlickerFreq.HZ100— 100 HzFlickerFreq.HZ120— 120 Hz
Bit layout of FD_STATUS: - bit 0: 100 Hz detected flag - bit 1: 120 Hz detected flag - bit 2: 100 Hz valid flag - bit 3: 120 Hz valid flag
- property gain: int
Analogue gain for spectral measurements.
Must be a
Gainvalue, e.g.Gain.X256. Default isGain.X256(256×).
- property gpio_output_mode: bool
Truewhen the GPIO pin is configured as an output.Set to
Falseto switch to input mode.
- property gpio_value: bool
GPIO pin state.
When in output mode, read back the driven value. When in input mode, read the external signal level.
- property integration_time_ms: float
Calculated integration time in milliseconds (read-only).
(atime + 1) × (astep + 1) × 2.78 µs
- property led_current_ma: int
LED drive current in milliamps.
Valid range: 4–258 mA (even values only; hardware steps of 2 mA). Formula:
current_mA = 4 + (register_value × 2)
- property persistence: int
Interrupt persistence filter (0–15).
Number of consecutive out-of-threshold measurements required before the interrupt flag is asserted. 0 = trigger every cycle.
- read_channel(channel: int) int
Read a single spectral channel by index.
Reads ASTATUS to latch data, then reads the specific channel register. Use
Channelconstants to specify the channel.
- property smux_mode: int
Auto-SMUX channel cycling mode.
Must be a
SmuxModevalue:SmuxMode.CH6— 6 channelsSmuxMode.CH12— 12 channelsSmuxMode.CH18— 18 channels (default)
- property status: int
Raw value of the main STATUS register (0x93).
Warning
Writing this register clears the status flags. Use
clear_status()to explicitly clear all flags.
- property threshold_channel: int
ADC channel (0–5) used for spectral interrupt threshold comparison.
Note
Hardware testing shows this register has no observed effect — threshold comparison always targets CH0 regardless of this setting. Read/write works correctly but the value is not acted upon by the hardware.
- class adafruit_as7343.CV
Constant-value helper used as an enum base class.
Subclasses define integer class attributes;
is_valid()andget_name()provide validation and reverse-lookup.
- class adafruit_as7343.Channel
Spectral channel index within the 18-channel auto-SMUX data array.
The index corresponds to the order in which data appears in the output buffer returned by
AS7343.all_channelsinSmuxMode.CH18mode.Setting
Index
Centre wavelength
Channel.FZ0
450 nm (blue)
Channel.FY1
555 nm (yellow-green)
Channel.FXL2
600 nm (orange)
Channel.NIR3
855 nm (near-IR)
Channel.VIS_TL_04
Clear, top-left, cycle 1
Channel.VIS_BR_05
Clear, btm-right, cycle 1
Channel.F26
425 nm (violet-blue)
Channel.F37
475 nm (blue-cyan)
Channel.F48
515 nm (green)
Channel.F69
640 nm (red)
Channel.VIS_TL_110
Clear, top-left, cycle 2
Channel.VIS_BR_111
Clear, btm-right, cycle 2
Channel.F112
405 nm (violet)
Channel.F713
690 nm (deep red)
Channel.F814
745 nm (near-IR edge)
Channel.F515
550 nm (green-yellow)
Channel.VIS_TL_216
Clear, top-left, cycle 3
Channel.VIS_BR_217
Clear, btm-right, cycle 3
- class adafruit_as7343.FlickerFreq
Flicker detection result values returned by
AS7343.flicker_frequency.Setting
Meaning
FlickerFreq.NONENo flicker detected
FlickerFreq.HZ100100 Hz mains flicker
FlickerFreq.HZ120120 Hz mains flicker
- class adafruit_as7343.Gain
Spectral measurement analogue gain settings for CFG1 register bits 4:0.
Higher gain increases sensitivity for low-light conditions but may saturate in bright environments.
Setting
Gain
Gain.X0_50.5×
Gain.X11×
Gain.X22×
Gain.X44×
Gain.X88×
Gain.X1616×
Gain.X3232×
Gain.X6464×
Gain.X128128×
Gain.X256256× ★
Gain.X512512×
Gain.X10241024×
Gain.X20482048×
★ Default after
AS7343.__init__().
- class adafruit_as7343.SmuxMode
Auto-SMUX channel-cycling mode settings for CFG20 register bits 6:5.
The auto-SMUX hardware automatically cycles through multiple SMUX configurations in a single measurement trigger, accumulating data for more spectral channels per access of
AS7343.all_channels.Setting
Channels measured
SmuxMode.CH66 channels (1 SMUX cycle)
SmuxMode.CH1212 channels (2 SMUX cycles)
SmuxMode.CH1818 channels (3 SMUX cycles) ★
★ Default after
AS7343.__init__().