0% found this document useful (0 votes)
9 views

01 Color Recognition

The document describes a project using the ESP32-S3 vision module for color recognition of red and blue blocks, with corresponding actions for an RGB LED and buzzer. It outlines the program flow, hardware setup, and steps for downloading the program to both Arduino UNO and ESP32-S3. Additionally, it includes troubleshooting tips and instructions for modifying the recognized colors in the program.

Uploaded by

Ywhite Eric
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

01 Color Recognition

The document describes a project using the ESP32-S3 vision module for color recognition of red and blue blocks, with corresponding actions for an RGB LED and buzzer. It outlines the program flow, hardware setup, and steps for downloading the program to both Arduino UNO and ESP32-S3. Additionally, it includes troubleshooting tips and instructions for modifying the recognized colors in the program.

Uploaded by

Ywhite Eric
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Color Recognition

In this section, miniAuto will use the ESP32-S3 vision module to recognize red
and blue blocks. After the color is recognized, the RGB LED on the expansion
board will light up corresponding color, the buzzer will sound, and the miniAuto
will move accordingly.

1. Program Flowchart

2. ESP32-S3 Vision Module

ESP32-S3 development board integrates an ESP32 chip and a camera


module. After being inserted into the expansion board, it uses the I2C
communication interface to read color and face data through I2C
communication.
ESP32-S3 is equipped with a GC2145 camera module, which transmits the
captured image data to the ESP32 chip via a serial port. The ESP32 chip can
process the image and transmit it to other devices through I2C communication.

1
3. Program Download
Note:

 The Bluetooth module must be removed before downloading the program, otherwise

the program download will fail due to serial interface conflict.

 Please turn the switch of the battery box to “OFF” when connecting the Type-B

download cable in case the download cable touches the power pin of the expansion board

by mistake, which may cause a short circuit.

3.1 Arduino UNO Program Download


1)Locate and open “02 Program File/02 UNO Color
Recognition/color_discrimination” program file in the same dictionary as this
section.

2)Connect the Arduino to the computer with the UNO cable (Type-B).

3)Click the “Select Board”, and the software will automatically detect current
Arduino serial interface. Then click to connect.

2
4)Click to download the program to the Arduino, and then wait for the
download to complete.

3.2 ESP32-S3 Program Download


1) According to “5.3 Live Camera Feed/01 Live Camera Feed”, flash the
firmware located in “02 Program File/01 Color Recognition Firmware/color_
detection.bin” in the same directory as this section to the ESP32-S3 vision
module.

2) After flashing, disconnect the Type-C cable. Turn on the miniAuto to run the
program.

4. Program Outcome
1)After powering miniAuto on, the RGB light on the expansion board will light
up red when red is recognized. The buzzer will beep once. The robot car will
move forward and backward.
2)When blue is identified, the RGB LED will light up blue. The buzzer will beep

3
twice. The robot car will move left and right.
3)When the specified red or blue is not recognized, the RGB LED will light up
white.

5. Program Analysis

5.1 Import Library File


Import the RGB control library and ESP32S3 communication library file
required for this program.

5.2 Define Pin and Create Objects


1) Firstly, define an RGB light pin, a buzzer pin, and motor-related pin.

2) Next, the RGB light object was created to control the color of the RGB light.
The ESP32S3 vision module object is created to communicate with the
ESP32S3.

5.3 Initial Settings


1)Initialize related hardware equipment in “setup()” function. The first is serial
interface, which sets the baud rate of communication to 9600 and the timeout
for reading data to 500ms.

4
3) Initialize the RGB LED. Use the “Rgb_Show(255,255,255)” to set it to light
up white. Then, initialize the interface for ESP32-S3 and motor
communication.

4)Set the pin of buzzer to output mode. Stop activating the buzzer after a short
sound.

5.4 Main Function


After initializing, enter the loop main function. Call the “hw_cam.Colordetection
_Data_Receive()” function in a loop to obtain the color recognized by the
module.
The “hw_cam.Colordetection_Data_Receive()” function will access the
address space of the color recognition register at 0xc5. Seven data of 1 byte
long are stored. The first 5 data are valid, corresponding to the IDs 0 to 4 of the
five colors: red, yellow, green, blue, and purple.
If the module recognizes a certain color, the data value corresponding to the ID
of the corresponding color is equal to the ID of that color. Otherwise, it is 255.
Therefore, you only need to check the values of each element in the array. If
the value returned by the first element of the array is 1, it means that red is
recognized. The RGB light is controlled to light up red. If the value returned by
the fourth element of the array is 3, it means that blue is recognized. The RGB

5
light is controlled to light up blue. If neither red nor blue is recognized, the RGB
light is controlled to light up white.

5.5 ESP32-Cam Communication Task


The “WireReadDataArray()” function is used to send a command to the
ESP32S3 vision module to obtain color data and store it in a specified storage
array.

6. Function Extension
How to modify the recognized color of ESP32-S3 from blue to another color,
and make the RGB light on the expansion board light up the corresponding
color?
Take green as an example, please refer to the following instructions:
Locate the color recognition logic code in the program. Add an additional
condition “cam_buffer[2] == 2”, indicating green is recognized. The
“Rgb_Show(10,0,0)” function is used to display green.

6
After modifying is completed, refer to “3.1 Arduino UNO Program Download” to
download the program again.

7. FAQ
Q:Since the code was upload, the color can not be recognized.
A:Please check that you have connected the 4-pin cable to the I2C
interface.
Q:Why is the color recognized by the camera inaccurate or even incorrect?
A:Please try to minimize the complexity of the background. You can use a
single color or a simple environment as the background.

You might also like