3.
1 Arduino and Vision Module
Interaction Routine
This section demonstrates how the ESP32-S3 vision module identifies
facial and other data and them transmit the data to the Arduino controller via
I2C protocol.
1. Working Logic
Taking a flowchart of the face recognition process as an example. In
practice, the implementation logic for color recognition and line tracking
functions is identical to that of facial recognition, with the only difference being
the data exchanged, which comes from different functional registers.
2. ESP32-S3 Vision Module
1
This is a development board that accommodates the EPS32 chip and a
camera module. Once the module is connected into the carrier board via I2C
communication interface, it is able to read the color and face data via I2C
communication.
2.1 Module Working Principle
The ESP32-S3 vision module includes a built-in camera module that
transmits the captured image data to the ESP32 chip via a serial interface. The
chip processes the images and transmits the data to other devices using I2C
communication.
2.2 Sensor Wiring
The wiring for ESP32-S3 vision module and Arduino UNO is shown in the
diagram below:
2
3. Program Download
3.1 Download Arduino UNO Program
1) Open the program file “Arduino_esp32S3cam.ino” in folder “3.2
Arduino_esp32S3cam” located in the same directory.
2) Connect Arduino to the PC using the Type-B data cable.
3) Click the option “Select board”. The software will automatically detect the
current Arduino serial port, and then click to connect.
3
4) Click to upload the program to Arduino and wait for the download to
complete. (Note: the program defaults to face recognition function. For
other functions, please refer to 5.3.)
3.2 Flash ESP32-S3 Vision Module Firmware
1) Reference to the content in “1. Tutorials/ 1. Introduction to EPS32-S3
Vision Module/ 1.2 Getting Started” and flash the firmware located in “3.3
ESP32-S3Cam_bin\face_detection.bin” into the ESP32-S3 vision module.
(This example uses face recognition. If you want to implement data reading for
color recognition or line following, you should flash 'color_detection.bin' or
'line_patrol.bin', respectively.)
4. Project Outcome
1) When the ESP32-S3 does not detect a human face, it will print all
zeros to the serial port.
4
2) Once detecting a human face, the module will print the obtained
internal data of a specific functional register to the serial port. (Note: Each line
represents the result of one round of collection and includes information from
all related functional registers.
Let's analyze one line as an example (see the blue box in the image below):
1. 8A 77: Center coordinates of the face detection box (138, 119)
2. 68 65: Center coordinates of the left eye (104, 101)
3. A9 5C: Center coordinates of the right eye (169, 92)
4. 8E 77: Center coordinates of the nose (142, 119)
5. 7B AB: Center coordinates of the left corner of the mouth (123,
171)
6. AB A3: Center coordinates of the right corner of the mouth (171,
163)"
5. Program Brief Analysis
Taking face recognition as an example, briefly introduce the
implementation logic of the program.
This example is named 'Arduino_ESP32S3cam.ino'. For details on the
program’s implementation logic, refer to the flowchart below:
5
5.1 Initialization
1) Firstly, import the communication library required for ESP32-S3 vision
module
2) Create a communication object for the ESP32-S3 vision module to
facilitate communication between Arduino UNO and ESP32-S3 vision module.
3) In the setup() function, it primarily initialize the relevant hardware
devices. First, initialize the serial port, setting communication baud rate to
115200 and the data read timeout to 500ms. Then, initialize the
communication with the ESP32-S3 vision module and set up the I2C
communication interface.
6
5.2 Loop Calling Child-function
Upon the completion of the initialization, enter the loop main function and
repeatedly call the “espcam_task” function to perform face recognition and
execute serial port printing task.
5.3 Vision Module Communication Task
Define the “espcam_task” function to perform face recognition and handle
serial port printing task.
1) First, the variables last_tick is defined to record the time of the last task
execution, while the res variable is used to store whether face data has been
detected (1 for yes, 0 for no).
2) The last_tick variable is used in combination with the millis() function
for delay operations. Specifically, the millis() function retrieves the current
runtime of the program, and the difference with the last_tick variable is
calculated. If the difference is less than 100, the function exits; if it is greater
than or equal to 100, it indicates that 100 ms has elapsed. The current time is
7
then assigned to the last_tick variable for the next delay operation."
3) Calling the faceDetect function of the “hw_cam” object to read the
detected face data from the EPS32-S3 vision module via I2C.
For the realization of color recognition or line following functionality, you
cam comment out this line and uncomment the corresponding line for desired
function.
When performing the color recognition and line following tasks, only the
functions called in section 5.3 differ; the internal implementation of these
functions is mostly identical. You can refer to the source code for details.