ESP32
CAM: How to set it up, How to access the TF card, and how to Free up
I/O! Why are all the pins connected to the Micro TF Card - meaning
you can't use any external I/O. Find out what to do to get usable I/O
pins as well as Micro TF Card operation!
ESP32 CAM:
How to test the setup of Your board (connection test).
How to setup the Webserver example and Stream Video.
How to get more I/O pins by configuring the TF card in 1 bit mode.
How to get an Extra Two More I/O (4 total) pins with minimal modification.
Why your code Fails to Compile (sometimes!).
Obviously, since this is an ESP32, you get all the internet capability
that it normally provides. You connect the camera module with the
flexible PCB connection clip. Simply flip up the clamp (black bit),
insert the flexible PCB and flip the clamp down.
Warning: You can buy the ESP32 CAM without a programming module.
You can buy an ESP32 CAM without a programming module, and whilst you can
connect up a serial link and other required connections manually, it is
far easier to buy a plug in programmer module that provides the serial
chip, reset and program push buttons and the USB connection.
The disadvantage of using a development board programmer is that all
the pins on the ESP32-CAM become inaccessible. So you will have to
unplug the ESP32-CAM and place it into a development board if you
want to develop a circuit.
Note: Using a development programmer board means you can't access pins.
The reason that you can buy them separately is that you can program the
chip and then remove the programmer for deployment. Also the module can
be programmed over WiFi if you are feeling particularly adventurous!
The image output format is jpg, BMP or grayscale, but you only get jpg output with an OV2640 camera module.
Note: jpg output is only available with an OV2640 camera module.
At the highest resolution (UXGA/SXGA) the ESP32 CAM (with OVO2640) is
capable of a 15fps (Frames per second) which is quite respectable.
Note that the camera is a 2Mpixel camera.
If you need a higher frame rate you can configure the CAM to operate in
SVGA mode for 30fps and CIF for 60fps - with the consequent reduction in
pixel width and height of the resulting images.
Also on the ES32-CAM PCB is a serial PSRAM, providing 8MBytes of RAM.
This is in addition to the 520kBytes of SRAM already in the ESP32 and is needed for the highest resolution images.
Feature Summary
- Ultra-small volume 802.11b/g/n Wi-Fi + BT/BLE SoC module.
- Uses low-power dual-core 32-bit CPU as an application processor.
- The main frequency can reach up to 240MHz, + computing power up to 600 DMIPS.
- Built-in 520KB SRAM and external 8MB PSRAM.
- Supports UART/SPI/I2C/PWM/ADC/DAC interfaces.
- Supports OV2640 and OV7670 cameras with built-in flash.
- Supports image WiFi upload.
- Supports TF card.
- Supports multiple sleep modes.
- Embedded Lwip and FreeRTOS.
- Supports STA/AP/STA+AP working mode.
- Supports Smart Config/AirKiss one-click network configuration.
- Supports serial port local upgrade and remote firmware upgrade (FOTA).
ESP32 CAM: Specification
Parameter
Value
Package
DIP-16
Dimensions
27*40.5*4.5 (±0.2) mm
SPI Flash
Default 32Mbit
RAM
Internal 520KB +
External 8MB PSRAM
Bluetooth
Bluetooth 4.2 BR/EDR
and BLE standards
Wi-Fi
802.11 b/g/n/e/i
Supported Interfaces
UART, SPI, I2C, PWM
Tf Card Support
Up to 4G
No of IO Ports:
9 - But see "The Schematic" below.
Default Serial Port Rate:
115200 bps
Image Output Format:
JPEG (only with OV2640),
BMP, Grayscale
Wifi Frequency range
2400 ~2483.5MHz
PCB antenna gain
2dBi
Current used: flashLED off
180mA@5V
Current used: flashLED on
310mA@5V
Current used: deep sleep
6mA@5V
Current used: modem sleep
20mA@5V
Current used: light sleep
6.7mA@5V
Power supply
4.75 ~ 5.25V
Operating temp. range
-20°C to +70°C
Setup the ESP32 CAM
Setup ESP32 Board Support
If you have not used an ESP32 board before you'll need to tell Arduino
IDE how to configure the ESP32 board. This is not specific to ESP32 CAM
but allows use of any ESP32.
You do this by adding a line of code in the "Additional Boards Manager
URLs" field of the File > Preferences Menu. This changes the Arduino
IDE to allow it to know about ESP32.
Here are the installation steps:
Open the Arduino IDE.
Go to Menu >File > Preferences.
In the Additional Boards Manager URLs field, enter the following URL:
This is the .json text to enter into the Additional Boards Manager text field below:
DO NOT USE >>>
https://dl.espressif.com/dl/package_esp32_index.json <<< DO NOT USE
<<< DO NOT USE
The above line is commonly found on the web!
Warning: The above json file is not maintained but it almost works!
If you set the "Additional Boards Manager" to the previous json file
then it installs ESP32 but only to version 1.0.6 - a lot of code will
appear to work. However I found this error when trying to use a file
system to access the TF card; using this example:
The solution is to use the 2nd json line above (the one that is not struck through - with green background).
Note: If you already have other .json files specified, then hit the
button on the right of the text box (see above image), and add the
.json text to a newline.
Complete setup by installing the ESP32 Espressif board manager:
Click OK.
Go to Tools > Board > Board Manager.
In the Board Manager window, search for ESP32.
Select the ESP32 by Espressif Systems board and click Install.
Once the board is installed, select it from the Board menu.
You are now ready to use the ESP32 with the Arduino IDE.
The main thing you will see in the IDE after adding the board, is that
in addition to the standard boards ("Arduino AVR boards"), you will have
an "ESP32" board entry as shown in the image below:
if you use an older IDE scroll down the boards manager to find "AI
Thinker EDP32-CAM". It is, however, a loooooooonnnng way down (there is an easier way - see below):
You can see there are a lot of boards to choose from - the easiest
way to select the correct board is using the with the new search
operation in the 2.x.x Arduino IDE - go back to the main IDE screen:
Select the drop down box under "Arduino Uno" that drops down a line labelled "Select other board and port":
...click it to pull up a convenient search box (in the image below).
Just search for "Ai thinker" and select "AI Thinker ESP32_CAM" and click
OK and the connected port.
Check the setup
Now lets use a very simple program to check that you can program the
ESP32-CAM. Lets just turn on and off the LED used as the flashlight.
This is on pin 4.
If you have now gone blind - you know its working! - 1s on and 1s off is too much!
Maybe we'll just not do that!!!
If you want a less bright option : lets just use the built in LED!!!!! -
actually I've turned on the LED for 100ms then off for 1s - still
blinding so lets use 1ms, 999ms off. Right, thats still bright if you
look at it (so don't!) but not too bad.
Note: To see the LED attached to GPIO33 look at the under side of the board.
To program the LEDs off (because that flashing LED is incredibly annoying), uncomment the line:
// #define TURN_OFF // uncomment this to turn off the LEDS
Here is the code:
// By John Main - TronicsBench.com
//
constintledPin=4;// FLASH LIGHT LED on GPIO4
constintredled=33;// Other LED on GPIO33
// #define TURN_OFF // uncomment this to turn off the LEDS
voidsetup(){
pinMode(redled,OUTPUT);
pinMode(ledPin,OUTPUT);
}
voidloop(){
// LED is wired to 3V3 via 1k res so inverted
#ifndef TURN_OFF
digitalWrite(redled,LOW);digitalWrite(ledPin,HIGH);
#endif
delay(1);
digitalWrite(redled,HIGH);
digitalWrite(ledPin,LOW);
delay(999);
}
File: led_blink-buit-in-or-flashled.ino
Note the LED on GPIO33 is effectively the LED_BUILTIN that you use on
other boards. The only problem is that the code for the AI Thinker ESP32
CAM does not define the "LED_BUILTIN" word so you have to specify
pin 33!
Camera Test program
Now use the provided example program to test out the camera's capabilities.
Use the sketch following the menu:
Menu > File > Examples >
(Examples for AI Thinker ESP32-CAM) > ESP32 > Camera > CameraWebServer
Add in your ssid and password and setup the camera model as below.
Select your specific setup
If you program the board thinking that everything is setup for you for
the AI Thinker board and camera then you will get this message
[E][camera.c:1113] camera_probe(): Detected camera not supported
[E][camera.c:1379] esp_camera_init(): Camera probe failed with error 0x20004
No need to panic: Just edit the following definitions that you can find at the top of the file:
// Select camera model
#defineCAMERA_MODEL_WROVER_KIT // Has PSRAM
//#define CAMERA_MODEL_ESP_EYE // Has PSRAM
//#define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM
//#define CAMERA_MODEL_M5STACK_V2_PSRAM // M5Camera version B Has PSRAM
//#define CAMERA_MODEL_M5STACK_WIDE // Has PSRAM
//#define CAMERA_MODEL_M5STACK_ESP32CAM // No PSRAM
// #define CAMERA_MODEL_AI_THINKER // Has PSRAM
//#define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM
Change to:
// Select camera model
// #define CAMERA_MODEL_WROVER_KIT // Has PSRAM
//#define CAMERA_MODEL_ESP_EYE // Has PSRAM
//#define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM
//#define CAMERA_MODEL_M5STACK_V2_PSRAM // M5Camera version B Has PSRAM
//#define CAMERA_MODEL_M5STACK_WIDE // Has PSRAM
//#define CAMERA_MODEL_M5STACK_ESP32CAM // No PSRAM
#defineCAMERA_MODEL_AI_THINKER // Has PSRAM
//#define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM
Also enter your ssid (wifi network name) and password (wifi network password )
constchar* ssid = "*********";
constchar* password = "*********";
Find out the network address
Program the ESP32-CAM and then open the serial monitor. The network
address of your ESP32-CAM will be shown on the serial monitor. If
nothing happens reset button on the programming board and wait for the
screen to update.
In the serial monitor you'll see something like this:
..............
WiFi connected
Starting web server on port: '80'
Starting stream server on port: '81'
Camera Ready! Use 'http://192.168.0.62' to connect
Just enter the TCPIP URL address, as shown above into your web browser - the numbers will be different for you.
This comprehensive program allows you to interact with a web page (controlled by the ESP32) to control many
options for the camera. The web-page you will see is shown in the image
below, along with the camera output:
Resulting example control web-page for the ESP32-CAM:
The drop down box at the top controls the image size (Resolution), where
you can change the screen size and view the resulting output.
To get a still image or a video stream, use buttons at the bottom of the screen.
It looks like the system is designed to be a stand alone camera with
storage, that connects to the web rather like a dash cam but connected
to the web.The thing is that you really need some controllable I/O pins to make a
system more useful and enable it to interact with other devices.
Header pins
Looking at the schematic there are tons of pins used to control the
camera and lots of pins used to connect to the Micro TF card. Virtually
every pin has a label and the two header pins expose 10 of these pins - 6
are power or ground.
There are two LEDs one is the "builtin" LED on GPIO33 and the other is
the LEDFlash on GPIO4. GPIO4 is also labelled HS2_DATA1 and connected to
TF card DATA1 which implies that this signal will not be used by the TF
card interface - maybe! The HS2_DATA1 (LEDFlash) signal is also routed to the P2
header - meaning its not going to be useful!
So that leaves 9 pins on the header that might be useful! This is
probably where the specification gets the entry "No of IO Ports: 9".
PSRAM
The PSRAM is connected (mainly) the dedicated ESP32 serial interface.
But CLK and CMD on this interface are not connected. Instead GPIO17
provides the PSRAM clock labelled PSRAM_CLK. This has probable been done
so that bit banged pins are used, allowing more control over the
interface.
U2RXD (also lablelled as IO16) is used as the PSRAM chip select going to header P1 pin 7.
Key concept for more I/O
For fast throughput the TF card uses SQI or Serial Quad Interface. It
means there are four data lines instead of just the one for SPI. You
can, however, configure the TF card to use less pins; either 2 or 1 bit,
meaning that the other 3 are free for use (1 bit mode).
The only thing this affects is the data throughput to the TF card and the fact that HS2_DATA1 is connected to the FLASH LED.
Getting Extra I/O
The entries in green are the easiest pins to use as external I/O.
Those in violet require a small amount of soldering.
Those in blue have a dual function (the serial port) that are used
during board programming. When not programming they can be used - but
really only if you remove the programming board and insert the ESP32 CAM
into a development board (or socket).
So you can get:
2 I/O for free - a programming change.
2 more I/O with a bit of soldering.
2 more I/O if you think about the serial port use.
Header pin assignments
The following table shows header pins that are not power or ground
Table showing Available I/O pins
Header pin name
Chip Name
Alternate name
Connected to
HS2_DATA0
GPIO02
IO2 (not used)
Micro TF
HS2_DATA1
GPIO04
n/a
Flash LED, Micro TF (easy mod.)
HS2_DATA2
GPIO12
n/a
Micro TF
HS2_DATA3
GPIO13
n/a
Micro TF
HS2_CLK
GPIO14
n/a
Micro TF
HS2_CMD
GPIO15
IO15 (not used)
Micro TF
U2RXD
GPIO16
IO16 (used)
PSRAM CS
CSI_MCLK
GPIO16
IO0 (not used)
Master clock for Camera, ESP32 BOOT.
U0TXD
U0TXD
n/a
not GPIO: ESP32 programming.
U0RXD
U0RXD
n/a
not GPIO: ESP32 programming.
LED
GPIO33
n/a
Requires h/w connection to P1 pin 4.
Note: (used), (not used) - the Netname may be used elsewhere in the schematic (or not).
The pins in green are easy to use as general purpose I/O, if TF Card used in 1 or 2 bit mode.
The pins in blue are serial programming pins - you could use them in a
target board with current limit resistors (if using a serial USB
programmer).
The pin in yellow - hold high for boot timeout - currently used in circuit for the CAM clock.
The pin in violet -requires hardware modification (see below) [GPIO4 is easiest].
Dual function pins
There are three dual function pins that have the potential to be used as GPIO.
Boot pin
The boot pin can be used after the boot timeout. But in this system,
it is used for the CAM master clock - so it is not really available for use
here!
Serial programming pins
If you use a programming development board and remove the ESP32 CAM
after programming then these pins can be used as GPIO. U0TXD can be
configured as GPIO1 and U0RXD can be configured as GPIO3.
U0TXD and U0RXD appear on header P1.
Extra pins using board modification
Extra pins that you could use for I/O (with a bit of work):
Description
Net Name
Chip
pin
Header pin
FLASH LED - remove R13 and use GPIO4 as a normal I/O. (VERY EASY as HS2_DATA1 is already connected to the header).
HS2_DATA1
GPIO4
P2 pin 6
Builtin LED (attached via 1k pull-up). Remove
pull-up R4, and solder wire from LED negative side to pin 4 of header
P1. Ensure R1 and R2 are not fitted.
LED
GPIO33
P1 pin 4
Expanding I/O using helper Chip
The other easy way to expand the I/O for this system is to use an
MCP23017 and this chip only requires 2 wires as it is an I2C device. So
you can easily expand the AI Thinker ESP32 CAM using the two easily
available pins GPIO12 and GPIO13.
By doing this you get a total of 14 fully usable I/O pins!
It is not essential but you should add an interrupt from the MCP23017. I
would add it to the LED FLASH pin (removing the resistor as detailed
above), as this pin is routed to the ESP32 header.
Easily setup 2 Free I/O pins
This is an easy software controlled way of changing the SQI
interface. Instead of using all 4 data pins you use only one. It is very
easy to do - just use the following inialisation code for the file
system library:
SD_MMC.begin("/sdcard", true)
The boolean flag 'true', indicates to the SD_MMC library to use 1-bit mode.
To use the other data lines as normal I/O just initialise them after the above line of code (See the example code below).
Arduino Sketch with 2 free I/O
The example code below uses the same example from here:
Files > Examples > SD_MMC > SDMMC_Test.ino
...but modifies it for the one bit mode. It also sets two pins GPIO12 and GPIO13 as outputs and toggles them alternately.
You can use those pins as you want i.e. input, input pulled high or output.
Download the test file here. This is a .txt file - download and save as a .ino file for use in the Arduino IDE.
How to get accurate DHT22 digital humidity sensor readings with an Arduino. Did you know it also measures temperature as Well? Find out why, in this page...
A PIR sensor lets your Arduino sense movement without contact. This tutorial covers PIR sensor basics, connecting one to an Arduino board and coding a motion detector.
Arduino Hall Effect Sensor: Add magnetic sensing superpowers to your Arduino projects with an easy-to-use hall effect sensor. With full code and layout...
Comments
Have your say about what you just read! Leave me a comment in the box below.
Don’t see the comments box? Log in to your Facebook account, give Facebook consent, then return to this page and refresh it.