AS7341
Works with
Any CircuitPython board with I2C
What it does
The AS7341 is a 10-channel spectral sensor that measures light intensity at 10 specific wavelength bands spanning 415nm to 680nm, plus a clear channel, a near-infrared channel, and a flicker detection channel. It functions as a pocket spectrometer — instead of just "how much light," it tells you the distribution of light across the visible spectrum. More complex to set up than a simple RGB sensor, but far more capable for color analysis, plant growth lighting, and spectral fingerprinting.
Installing the library
Download the adafruit_as7341/ folder from the Adafruit CircuitPython Bundle and copy the entire folder to the lib/ folder on your board.
Quick start
import board
import busio
import adafruit_as7341
i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_as7341.AS7341(i2c)
sensor.start_measurement()
channels = sensor.all_channels
labels = ["415nm", "445nm", "480nm", "515nm", "555nm",
"590nm", "630nm", "680nm", "clear", "NIR"]
for label, value in zip(labels, channels):
print(f"{label}: {value}")
Key things you can do
| What you want | How to do it |
|---|---|
| Start a measurement | sensor.start_measurement() — required before reading |
| Read all 10 channels at once | sensor.all_channels — returns a tuple of 10 values |
| Read a specific wavelength | sensor.channel_415nm, sensor.channel_445nm, sensor.channel_480nm, etc. |
| Read the clear channel | sensor.channel_clear |
| Read near-infrared | sensor.channel_nir |
| Detect flicker frequency | sensor.flicker_detected, sensor.flicker_detection_enabled |
| Adjust gain | sensor.gain — options from GAIN_0_5X to GAIN_512X |
| Adjust integration time | sensor.atime and sensor.astep control the integration period |
Reading the official docs
Full API reference: https://docs.circuitpython.org/projects/as7341/en/latest/
Key things to look up:
start_measurement()must be called before reading — without it, channels return stale or zero valuesall_channelsreads all 10 spectral channels in two internal passes (the chip has two banks of photodiodes); individual channel properties are more convenient but slower when reading many channelsatimeandasteptogether determine integration time:t = (atime + 1) * (astep + 1) * 2.78µs- Flicker detection identifies 50Hz or 60Hz flicker from artificial lighting — useful for filtering out interference
Projects using this library
- Adafruit AS7341 guide — wiring, setup, and spectral reading examples