A step by step guide to setting up the Ai-Thinker ESP32-CAM with Espressif’s ESP32 development environment and the ESP-WHO libraries for face detection and recognition.
With this module you get face detection for ~ $7! They have them on AliExpress here.
The AI-Thinker ESP32-CAM module features an ESP32-S chip, an OV2640 camera and a microSD card slot. The software needs to be compiled and uploaded using the Espressif development environment.
Follow the steps below to download and install everything you need to develop on the ESP32 including packages for the ESP-IDF and the ESP32 toolchain. If you prefer to use the Arduino IDE (it’s a lot easier to set up the web server demo) there’s another tutorial here: ESP32-CAM using Arduino IDE
ESP32 IDF Development Environment
Download the all-in-one toolchain and msys32 environment from here:
Create a new directory in your C drive called msys32.
Unzip the contents of download to this new directory.
Navigate to C:\msys32\ and double-click mingw32.exe to open a terminal.
In this terminal type or paste each command below:
mkdir -p ~/esp
git clone -b v3.3.1 --recursive https://github.com/espressif/esp-idf.git
If you look in c:\msys32\home\**yourusername**\esp\ you will see all the APIs and libraries for the ESP32 have been installed.
A user profile script needs to be added so projects will build without the path to these files having to be entered every time.
Find the path to the ESP-IDF. Following this tutorial it will be C:\msys32\home\**yourusername**\esp\esp-idf\
Create a new file named export_idf_path.sh in C:/msys32/etc/profile.d/
Open it in Notepad and add the following line to the new export_idf_path.sh file replacing the IDF_PATH with your own. Check you are using forward slashes.
Save and close this new file.
Close the MSYS2 terminal window and then double click mingw32.exe to open it again. Check if
IDF_PATH is set by typing:
To complete set up, paste the following commands in the MSYS2 terminal window
pacman -S mingw-w64-i686-python2-cryptography
python2.7 -m pip install --user -r C:/msys32/home/**yourusername**/esp/esp-idf/requirements.txt
The ESP32 development environment is now set up.
ESP-WHO Face Detection and Recognition Libraries
To set up the face detection and recognition libraries and demos, type or paste the following commands in the MSYS2 terminal window
git clone --recursive https://github.com/espressif/esp-who.git
If you look in c:\msys32\home\**yourusername**\esp-who\ you will see the ESP-WHO libraries and examples have been installed.
The ESP32-CAM doesn’t come with a USB connector so you need either a CP2102 or a FT232RL USB to TTL Serial Converter to connect it to your PC. When using WiFi the ESP32 can use more current than is supplied via USB through these devices resulting in the module crashing and rebooting. I found the top device worked fine (I bought it here) but the FT232RL wouldn’t work without a separate supply to the 5V pin. If you use a FT232 with 5v and 3.3v, set the voltage jumper to 3.3v so the serial connections are at 3.3v. You might be able to use the 5V from the side of the board to power the 5v pin on the camera.
Wire the module according to the diagram above and plug into your PC. The green connection should be connected when flashing the module and disconnected when running.
Open Device Manager and make a note of the port number of the serial converter:
Camera Web Server Example
In the MSYS2 terminal window type or paste the following:
In the window that opens you need to change the following settings
Serial flasher config —> Default serial port (Change to the port number shown in Device Manager – ie COM3)
Camera Web Server —> WiFi Settings —> (Add your WiFi SSID and Password)
Camera Web Server —> Camera Pins —> Select Camera Pinout —> (Select ESP32-CAM by AI-Thinker)
Component config —> ESP32-specific —> SPI Ram config —> Type of SPI RAM chip (Select Auto-detect)
Save the configuration.
In the terminal window, type:
If you get an error that the device fails to connect. Check that the IO0 pin (green in the diagram) is connected to GRD and press the reset button under the module and try again.
When the device has completed flashing. Unplug IO0 from GND and type:
Press the reset button on the ESP32-CAM and watch the start up sequence in the terminal.
Look for the IP address the ESP32 has been given on your network camera wifi where it outputs got ip:xxx.xxx.xxx.xxx
Type that IP address into your browser. You should be able to see a GUI on the left where you can control elements of the camera, set face detection and face recognition. Click Get Still to take a photo. Click Start Stream to see a video stream from the camera.
It’s worth checking the jumper next to the IPEX connector on the bottom of the board to make sure it’s set for the internal aerial otherwise you may see low frame-rates and poor reception.
Here’s a list of resources that I used to get this working
If you liked this tutorial and want me to create more then please say thanks by buying me a coffee here...