【Gravity:AS7341 Review】+ Design of Color Detector (and Final Report)
[Copy link]
Sending the detection value of the visible light sensor to the serial port for output display is always inconvenient in use. If it is equipped with a small display screen, it will be improved. Figures 1 to 3 show the display effect after configuring the OLED display screen.
Figure 1 Start screen
Figure 2 Display of the first 4 channel values
Figure 3 shows the values of the last four channels
To realize such a display function, it is nothing more than adding an OLED screen display driving function on the basis of the original color detection.
To this end, we can establish the following connection relationship between the two I2C pins of the OLED screen and the MCU :
SCL1---12
SDA1---11
The statements for using I/O to simulate the high and low levels output by I2C communication are defined as:
#define SCL1_high digitalWrite(SCL1, HIGH)
#define SCL1_low digitalWrite(SCL1,LOW)
#define SDA1_high digitalWrite(SDA1, HIGH)
#define SDA1_low digitalWrite(SDA1,LOW)
The statement to set two pins as output functions is:
pinMode(SCL1, OUTPUT);
pinMode(SDA1, OUTPUT);
The relevant function for auxiliary data transmission is:
void IIC_Start()
{
SCL1_high;
SDA1_high;
SDA1_low;
SCL1_low;
}
void IIC_Stop()
{
SCL1_low;
SDA1_low;
SCL1_high;
SDA1_high;
}
void IIC_Wait_Ack()
{
SCL1_high;
SCL1_low;
}
The key procedures to achieve the display effect are:
void setup(void)
{
Serial.begin(115200);
while (as7341.begin() != 0) {
Serial.println("IIC init failed, please check if the wire connection is correct");
delay(1000);
}
pinMode(SCL1, OUTPUT);
pinMode(SDA1, OUTPUT);
OLED_Init();
OLED_Clear();
OLED_ShowString(0,0,"AS7341 TEST",16);
OLED_ShowString(0,2,"jinglixixi",16);
delay(1000);
delay(1000);
OLED_Clear();
OLED_ShowString(0,0,"F1=0 F2=0",16);
OLED_ShowString(0,2,"F3=0 F4=0",16);
delay(1000);
delay(1000);
OLED_ShowString(0,0,"F5=0 F6=0",16);
OLED_ShowString(0,2,"F7=0 F8=0",16);
}
void loop(void)
{
DFRobot_AS7341::sModeOneData_t data1;
DFRobot_AS7341::sModeTwoData_t data2;
as7341.startMeasure(as7341.eF1F4ClearNIR);
data1 = as7341.readSpectralDataOne();
OLED_Clear();
OLED_ShowString(0,0,"F1= F2=",16);
OLED_ShowString(0,2,"F3= F4=",16);
OLED_ShowNum(24,0,data1.ADF1,4,16);
OLED_ShowNum(88,0,data1.ADF2,4,16);
OLED_ShowNum(24,2,data1.ADF3,4,16);
OLED_ShowNum(88,2,data1.ADF4,4,16);
as7341.startMeasure(as7341.eF5F8ClearNIR);
data2 = as7341.readSpectralDataTwo();
delay(1000);
delay(1000);
OLED_Clear();
OLED_ShowString(0,0,"F5= F6=",16);
OLED_ShowString(0,2,"F7= F8=",16);
OLED_ShowNum(24,0,data2.ADF5,4,16);
OLED_ShowNum(88,0,data2.ADF6,4,16);
OLED_ShowNum(24,2,data2.ADF7,4,16);
OLED_ShowNum(88,2,data2.ADF8,4,16);
delay(1000);
delay(1000);
}
FIG. 4 is a color distribution interval, and corresponding color detection is performed. Corresponding color samples are extracted for display on the display screen, as shown in FIG. 5 .
Figure 4 Color distribution interval
Figure 5 Color samples (F3)
The results of color sample detection using visible light sensor are as follows:
1 ) F1 color sample
RGB(888) color value:
0x8B3DC5=( 10001 011, 001111 01, 11000 101)B
RGB(565) color value:
0x89F8
Measured value:
F1 =3
|
F2 =42 (1)
|
F3 =13
|
F4 =12
|
F5 =16
|
F6 =25 (2)
|
F7 =18 (3)
|
F8 =9
|
2 ) F3 color samples
RGB(888) color value:
0x01 B0 F1=( 00000 001, 101100 00, 11110 001)B
RGB(565) color value:
0x059E
Measured value:
F1 =4
|
F2 =57 (1)
|
F3 =20
|
F4 =27 (3)
|
F5 =29 (2)
|
F6 =12
|
F7 =5
|
F8 =3
|
3 ) F5 color samples
RGB(888) color value:
0x00AF50=( 00000 000, 101011 11, 01010 000)B
RGB(565) color value:
0x056A
Measured value:
F1 =2
|
F2 =12
|
F3 =8
|
F4 =19 (2)
|
F5 =33 (1)
|
F6 =13 (3)
|
F7 =4
|
F8 =2
|
4 ) F7 color samples
RGB(888) color value:
0x FF C0 00=( 11111 111, 110000 00, 00000 000)B
RGB(565) color value:
0xFE00
Measured value:
F1 =5
|
F2 =9
|
F3 =11
|
F4 =32
|
F5 =41 (3)
|
F6 =69 (1)
|
F7 =48 (2)
|
F8 =22
|
5 ) F6 color samples
RGB(888) color value:
0x FF FF 01=( 11111 111, 111111 11, 00000 001)B
RGB(565) color value:
0xFFE0
Measured value:
F1 =4
|
F2 =7
|
F3 =11
|
F4 =42
|
F5 =88 (2)
|
F6 =92 (1)
|
F7 =54 (3)
|
F8 =26
|
6 ) F8 color samples
RGB(888) color value:
0x C1 00 03=( 11000 001, 000000 00, 00000 011)B
RGB(565) color value:
0xC000
Measured value:
F1 =1
|
F2 =4
|
F3 =3
|
F4 =2
|
F5 =7
|
F6 =29 (1)
|
F7 =23 (2)
|
F8 =9 (3)
|
7 ) F2 color samples
RGB(888) color value:
0x02 51 8C =( 00000 010, 010100 00, 10001 100)B
RGB(565) color value:
0x0291
Measured value:
F1 =2
|
F2 =34( 1)
|
F3 =12 (2)
|
F4 =12 (3)
|
F5 =11
|
F6 =5
|
F7 =3
|
F8 =1
|
8 ) F4 color sample
RGB(888) color value:
0x02 FE CD =( 00000 010, 111111 10, 11001 101)B
RGB(565) color value:
0x0291
Measured value:
F1 =7
|
F2 =67 (3)
|
F3 =30
|
F4 =73 (2)
|
F5 =74 (1)
|
F6 =22
|
F7 =7
|
F8 =4
|
After actual evaluation, the performance of the visible light sensor AS7341 is quite outstanding, especially in the recognition of yellow, which can be recognized independently instead of the sum of two colors. It is a pity that the original intention was to use a color OLED screen to complete the design of the color recognition instrument, but the program storage space of the Arduino UNO development board is slightly smaller and cannot support the realization of this idea. Although there is no problem in driving the color OLED alone to complete the display output, after adding the color sensor, it can only display the starting interface, and the sensor cannot operate in the limited program space. The solution is to transplant the program function of Arduino UNO to the MCU development board with a larger program storage space , of course, this takes more time.
|