Repository navigation
esp_as7341 esp‐idf component
Koios edited this page Nov 9, 2025
·
1 revision
Documentation for the ESP-IDF driver for the AMS AS7341 11-channel spectrometer as implemented in as7341.h.
This component provides an ESP-IDF compatible driver for the AMS AS7341 I2C spectrometer—an 11-channel sensor covering visible and NIR wavelengths. It has facility for spectral data acquisition, flicker detection, gain and timing adjustment, LED control, and power management.
- Supported Device: AMS AS7341 Spectrometer
- Platform: ESP32-S3 (ESP-IDF)
- Protocol: I2C
MIT License
Copyright (c) 2024 Eric Gionet
See LICENSE for details.
- Read raw spectral measurements from 8 bands (F1–F8), plus clear and NIR channels
- Gain and timing configuration (ATIME, ASTEP, spectral gain)
- Power and LED control
- Flicker detection (100 Hz / 120 Hz)
- Sensing mode selection
- Buffer and basic conversion between spectral data and normalized "counts" (floats)
- Extended hardware features: SMUX, interrupt, wait time, etc.
- Firmware version query functions
#include "as7341.h"
as7341_config_t config = AS7341_CONFIG_DEFAULT;
as7341_handle_t spectrometer;
esp_err_t ret = as7341_init(master_i2c_bus, &config, &spectrometer);
if (ret == ESP_OK) {
as7341_channels_spectral_data_t raw;
as7341_get_spectral_measurements(spectrometer, &raw);
as7341_channels_basic_counts_data_t counts;
as7341_get_basic_counts(spectrometer, raw, &counts);
// Use counts.f1...counts.nir
}-
AS7341_CONFIG_DEFAULT#define AS7341_CONFIG_DEFAULT { \ .i2c_address = I2C_AS7341_DEV_ADDR, \ .i2c_clock_speed = I2C_AS7341_DEV_CLK_SPD, \ .spectral_gain = AS7341_SPECTRAL_GAIN_32X, \ .power_enabled = true, \ .atime = 29, \ .astep = 599 \ }
- Fast-start values for gain, timing, and power.
| Name | Value | Description |
|---|---|---|
| I2C_AS7341_DEV_CLK_SPD | 100000 | I2C SCL frequency (Hz) |
| I2C_AS7341_DEV_ADDR | 0x39 | Device I2C address |
-
ALS Modes:
-
AS7341_ALS_SPM_MODE(default, spectral measurement mode) AS7341_ALS_SYNS_MODEAS7341_ALS_RESERVED_MODEAS7341_ALS_SYND_MODE
-
-
LED Drive Strengths:
-
AS7341_LED_DRIVE_STRENGTH_4MA...AS7341_LED_DRIVE_STRENGTH_258MA
-
-
Spectral Gains:
-
AS7341_SPECTRAL_GAIN_0_5X, ...,AS7341_SPECTRAL_GAIN_512X
-
-
Flicker Detection Gains/States:
-
AS7341_FLICKER_DETECTION_GAIN_0_5X...512X -
AS7341_FLICKER_DETECTION_INVALID,UNKNOWN,SATURATED,100HZ,120HZ
-
-
SMUX Commands:
-
AS7341_SMUX_CMD_ROM_RESET,READ,WRITE
-
| Field | Range (nm) |
|---|---|
f1 |
405–425 |
f2 |
435–455 |
f3 |
470–490 |
f4 |
505–525 |
f5 |
545–565 |
f6 |
580–600 |
f7 |
620–640 |
f8 |
670–690 |
clear |
- |
nir |
- |
| Field | Range (nm) | Description |
|---|---|---|
f1 |
405–425 | Float |
| ... | ... | ... |
nir |
- | Float |
| Field | Type | Description |
|---|---|---|
i2c_address |
uint16_t |
I2C device address |
i2c_clock_speed |
uint32_t |
SCL frequency (Hz) |
atime |
uint8_t |
Integration step count |
astep |
uint16_t |
Integration time step |
spectral_gain |
as7341_spectral_gains_t |
Gain multiplier |
power_enabled |
bool |
Power on/off |
as7341_init(i2c_master_bus_handle_t, const as7341_config_t *, as7341_handle_t *)as7341_remove(as7341_handle_t)as7341_delete(as7341_handle_t)
-
as7341_get_spectral_measurements(as7341_handle_t, as7341_channels_spectral_data_t *)- Read raw data for F1–F8, clear, and NIR.
-
as7341_get_basic_counts(as7341_handle_t, const as7341_channels_spectral_data_t, as7341_channels_basic_counts_data_t *)- Convert raw spectral data to normalized float counts.
-
as7341_enable_flicker_detection(as7341_handle_t),as7341_disable_flicker_detection(as7341_handle_t) as7341_get_flicker_detection_status(as7341_handle_t, as7341_flicker_detection_states_t *)
-
as7341_set_spectral_gain,as7341_get_spectral_gain -
as7341_set_atime,as7341_get_atime -
as7341_set_astep,as7341_get_astep
- ALS mode:
as7341_set_ambient_light_sensing_mode,as7341_get_ambient_light_sensing_mode - Power:
as7341_enable_power,as7341_disable_power - LED:
as7341_enable_led,as7341_disable_led - Spectral measurement:
as7341_enable_spectral_measurement,as7341_disable_spectral_measurement - SMUX and wait time enable/disable
as7341_get_data_status(as7341_handle_t, bool *ready);
as7341_get_fw_version()as7341_get_fw_version_number()
<esp_err.h><driver/i2c_master.h>"as7341_version.h""type_utils.h"
Copyright (c) 2024 Eric Gionet (gionet.c.eric@gmail.com)