• sales

    +86-0755-88291180

AS7341 Spectral Color Sensor spotpear

Introduction

With AS7341 visible spectrum sensing IC as the core. this product can sense the visible light component values of different bands in the environment. It is also quite impressive in sensitivity and accuracy. At the same time, its volume is very small. To make a miniature spectrum analyzer, it will be a very good choice.

Feature

  • Incorporates AS7341 chip, which integrates 8x visible spectrum channels, 1x near infrared channel, and 1x no filter channel
  • Embedded 6x independent 16-bit ADC, allows effectively processing data in parallel
  • Dedicated channel to detect ambient light flicker on the specific frequency
  • 2x high brightness LEDs, can be used as fill light on the dim environment
  • Interrupt pin to output inner ADC real time operating status
  • Features spectrum interrupt detection, with programable high/low thresholds
  • Provides general purpose input/output GPIO pin
  • Onboard voltage translator, compatible with 3.3V/5V operating voltage
  • Comes with development resources and manual (examples for Raspberry Pi/Arduino/STM32)

Specification

  • Operating voltage: 3.3V/5V
  • Operating current: 20mA (without open the LED) 70mA (when open the LED)
  • Sensor: AS7341
  • Logical voltage: 3.3V/5V
  • Interface: I2C
  • Dimension: 30.5mm x 23mm
  • Mounting hole size: 2.0mm

Pinout

Pin numberPINDescription
1VCC3.3V/5V Power input
2GNDGround
3SDAI2C data line
4SCLI2C clock line
5INTInterrupt output pin
6GPIOinput/output GPIO port

Hardware description

AS7341 Chip

This product uses AS7341-DLGM as the core, which is an 11-channel IC for spectrum recognition and color matching applications. The spectral response is defined at a wavelength of about 350nm to 1000nm. 6 channels can be processed in parallel by independent adcs, while the other channels can be accessed through a multiplexer. AS7341 integrates the filter into the silicon of standard CMOS through a nano-optical deposition interference filter. The technology and its package provide a built-in aperture to control the light entering the sensor array. Its control and spectral data access are realized through the serial I²C interface.

Working Protocol

This product uses I2C communication with one data line and one clock line. There are three types of signals in the I2C bus in the process of transmitting data: START signal, STOP signal, and Response signal.


START signal: When SCL is high level, SDA jumps from high to low to start transmitting data.
STOP signal: When SCL is high level, SDA jumps from low level to high level, ending the data transmission.
Response signal: After receiving the 8bit data, the data receiving IC sends a specific low-level pulse to the data sending IC to indicate that the data has been received.

  • I2C write data timing


First, the host(ie, Raspberry Pi) will send a start signal, and then combine its I2C 7-bit address and write operation bits into 8-bit data and send it to the slave (ie TSL2581 sensor module), the slave will respond with a response signal after receiving it. The host sends the command register address to the slave, and then the slave receives this response signal. At this time, the master sends the value of the command register and the slave responds with a response signal. Until the host sends a STOP signal, the I2C write data operation ends

  • I2C read data timing


First, the host will send a START signal, and then combine its I2C 7-bit address and write operation bit into 8-bit data and send it to the slave. After receiving it, the slave will respond with a response signal, and the host will send the command register address at this time. After the slave receives the sending response signal, the host will send a START signal again, and combines its 7-bit address and read operation bit into 8-bit data and sends it to the slave. The slave sends a response after receiving the signal, then sends the value in its register to the host. And the host gives a response signal until the host sends a stop signal, and this communication ends.

  • I2C address

The I2C device address of AS7341 is 0X39 which you can check on page 21 of the AS7341 data sheet.


This example is tested on Arduino UNO. If you use other models of Arduino, please pay attention to whether the related pins are connected correctly.

Hardware connection


Run the demo

  • After downloading the demo, unzip this .7z file on your PC.
  • The Arduino program is located in ~/Arduino/... Copy the Waveshare_AS7341 folder from this directory to the libraries in the Arduino installation directory, usually in C:\Users\XXX\Documents\Arduino\libraries or C:\Program Files (x86)\Arduino \libraries.
  • Open Arduino IDE, click File->Example, and check whether there has Waveshare_AS7341 option.
  • If the Waveshare_AS7341 library is imported successfully, open the ino project file in the Arduino/Waveshare_AS7341/example
  • Select the corresponding model of the development board and COM port, compile the program, and then download it to UNO, and open the serial monitor.

  • Demo phenomena:

Demo description

There are several different test projects on the Arduino/Waveshare_AS7341/example directory, here we give some describes and precautions.

  • AS7341_Getdata is used to obtain 10 channels of test data. AS7341 has only 6 independent ADCs, but it has 11 channels, which requires multiplexer SMUX. For related configuration, please refer to the reference code of the datasheet manual.
  • AS7341_Getdata includes the driver code to turn on the fill light LED and adjust the brightness
//AS7341_EnableLED(true);// LED ON or OFF
//AS7341_ControlLed(10);//Adjust the brightness of the LED lamp

If you need to use LED fill light, just comment these two lines of code

  • AS7341_Getflicker is used to detect 100 or 120Hz ambient light flicker, you need to generate a flickering light of this frequency by yourself. Adjust the integration time, gain, etc. to detect flicker of different frequencies。
  • AS7341_Syns configures the sensor mode as SYNS mode. In this mode, the GPIO port of the sensor needs to receive a falling edge signal to trigger measurement, and each falling edge triggers a measurement.

This module does not directly connect the GPIO port by default. Therefore, during your testing, you can briefly touch the GPIO port with the 3.3v or 5V pin of the development board and then disconnect it to obtain a falling edge signal. And in your actual use, you can connect the GPIO port to the trigger source directly.

while(!AS7341_MeasureComplete());   // Jump out of this loop when GPIO receives a valid signal.
  • AS7341_INT is the spectrum interrupt test. It sets the upper and lower thresholds for interrupt generation. At the same time, you can set the channel triggered by the interrupt. The channel selection can be one of CH0-CH4. When the interrupt is triggered by the change of ambient light, read the value of the relevant register to check whether it is triggered.
AS7341_SetInterruptPersistence(0);   // Set the sensitivity of spectrum interruption
AS7341_SetSpectralThresholdChannel(4);  //Set the channel to detect interrupts
  • AS7341_pinINT is an experiment on the INT pin on the module. After each measurement of AS7341, the INT pin will become low level. You can configure the relevant register to set how often the sensor measures the environmental spectrum data, which also determines the INT pin How often does the foot jump. In this demo, the measurement time is set to 1s, and the level status of the INT pin is monitored at the same time.
  • AS7341_Clear is to reset all the register enable bits that are turned on in the AS7341.

This demo has been verified on NUCLEO-F103RB (chip model STM32RBT6) and OpenH743I-C (chip model STM32H743IIT6). If you need to migrate to other boards, please pay attention to the relevant configuration and Hardware connection.

Hardware connection


AS7341 Spectral Color SensorXNUCLEO-F103RB
VCC3.3V/5V Power input
GNDGround
SDASDA/D14/PB9
SCLSCL/D15/PB8
INTD8/PA9
GPIO/

Hardware connection with OpenH743I-C

AS7341 Spectral Color SensorOpenH743I-C
VCC3.3V/5V Power input
GNDGround
SDAPD13(I2C4 SDA)
SCLPD12(I2C4 SCL)
INTPD11
GPIO/

Demo description

After downloading the demo, unzip this .7z file on your PC. The STM32 demo is located in ~/ STM32/… . You can see the two folders NUCLEO-F103RB and OpenH743I-C.

NUCLEO-F103RB

  • Open STM32\XNUCLEO-F103RB\MDK-ARM\demo.uvprojx on the demo folder, this demo uses HAL library.
  • If you need to change the chip or want to use the standard library, you just need to change DEV_Config.c and .h to implement the functions and macro definitions inside. The chip can also be configured by using STM32CubeMX. This demo uses serial port 2 (PA2, PA3) to output data.
  • The serial port baud rate is 115200, and other options use the default values: 8 data bits, 1 stop bit, and no parity bit. The serial port assistant tool is provided in the folder.

OpenH743I-C

  • Open STM32\OpenH743I-C\MDK-ARM\I2C.uvprojx, this demo also uses HAL library.The two are different in terms of chip signals and peripheral configuration, but the test demo used are exactly the same. Here we take OpenH743I-C as an example.
  • Open main.c in the project, uncomment the program that needs to be tested. Shown as the picture below:
  • Connect the downloader, connect the serial data line to USART1, click compile to download and verify.
  • The related program usage and instructions have been explained in the Arduino tutorial, you can check it on the Arduino chapter page.
  • Test result:

This example uses Raspberry Pi 3 Model B, provides BCM2835, WiringPi, file IO, RPI (Python) library demos.

Hardware connection


AS7341 Spectral Color SensorRaspberry Pi (BCM)
VCC3.3V/5V Power input
GNDGround
SDASDA(2)
SCLSCL(3)
INT4
GPIO/

Working with Raspberry Pi

Enable I2C interface

  • Open terminal, use command to enter the configuration page
sudo raspi-config
Choose Interfacing Options -> I2C -> Yes  to enable I2C interface


And then reboot the system:

sudo reboot

Libraries Installation

  • Install BCM2835 libraries
wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.68.tar.gz
tar zxvf bcm2835-1.68.tar.gz 
cd bcm2835-1.68/
sudo ./configure && sudo make && sudo make check && sudo make install

For more details, please refer to http://www.airspayce.com/mikem/bcm2835/

  • Install wiringPi libraries
sudo apt-get install wiringpi

#For Pi 4, you need to update it:
wget https://project-downloads.drogon.net/wiringpi-latest.deb
sudo dpkg -i wiringpi-latest.deb
gpio -v
#You will get 2.52 information if you install it correctly

Download the demo

Open the terminal of the Raspberry Pi, execute command to download demo codes:

sudo apt-get install p7zip-full
wget https://www.waveshare.com/w/upload/b/b3/AS7341_Spectral_Color_Sensor_code.7z
7z x AS7341_Spectral_Color_Sensor_code.7z -r -o./AS7341_Spectral_Color_Sensor_code
sudo chmod 777 -R  AS7341_Spectral_Color_Sensor_code

C

cd AS7341_Spectral_Color_Sensor_code/AS7341_Spectral_Color_Sensor_code/RaspberryPi/c
make clean
make

Enter the following command to execute the demo:

sudo ./main data
  • 【Note】The 'data' here can be changed to flicker, syns, int, pinint, clear to verify different test demos, and its meaning is explained in the code.
  • Take the execution of sudo ./main data as an example, the test result is:

python

cd
cd AS7341_Spectral_Color_Sensor_code/AS7341_Spectral_Color_Sensor_code/RaspberryPi/python/examples

Enter the following command to execute the demo:

sudo python data.py
  • 【Note】The 'data' here can be changed to flicker, syns, int, pinint, clear to verify different test demos, and its meaning is explained in the code.
  • Take the execution of data.py as an example, the test result is:

Demo description

The functions of all test demos and the points that need attention have been introduced in the Arduino tutorial. When executing sudo ./main syns or python syns.py, you need to pull up the GPIO port and then pull it down to generate a falling edge signal. You can connect the GPIO pin to the high-level pin for a short time and then released to generate a falling edge signal.