Basics project 084g ESP32-CAM Development Board – How to adjust camera settings


Basics: Project 084g

Project name: ESP32-CAM Development Board – How to adjust OV2640 camera settings

Tags: Arduino, Arduino Uno, Ai-Thinker, ESP32-CAM, Development Board with camera, OV2640, how to adjust camera settings

Attachments: sketch

In this project, you needed these parts (Dear visitors. You can support our project buy clicking on the links of parts and buying them or donate us to keep this website alive. Thank you):

1. ESP32-CAM Development Board with camera 1 set

esp32-cam

2. Arduino IDE ( you can download it from here  )

3. USB to TTL/Serial adaptor/converter 1 pc

USB to TTL converters
USB TO TTL converters

4. Jumper cables F-F

5. Micro SD card and SD card adapter 1 pc

6. WiFi AntennaCompact Internal WiFi Antenna with U.FL connector and 5.9 inch cable 1 pc (optional)

7. External 5V power supply for ESP32-CAM 1 pc (optional)

General

We will learn in this project how to adjust the ESP32-CAM Development Board OV2640 camera settings such as contrast, brightness, resolution, quality, saturation and so on using Arduino IDE. This project is valid for any ESP32 camera development board with the OV2640 camera.

In our project Basics: Project 084a ESP32-CAM Development Board with camera – Camera Web Server with Arduino IDE, you can see that the web server provides a lot of options to change the image settings.

ESP32CAM

We will show you how to adjust an image settings in your code, which you can use for taking pictures or streaming video projects with ESP32-CAM development board.

Understanding the USB to TTL converter

You can read more about them here.

Understanding the ESP32-CAM Development Board with camera

The ESP32-CAM has a very competitive small-size camera module that can operate independently as a minimum system with a footprint of only 27*40.5*4.5mm and a deep sleep current of up to 6mA.

ESP32-CAM can be widely used in various IoT applications. It is suitable for home smart devices, industrial wireless control, wireless monitoring, QR wireless identification, wireless positioning system signals and other IoT applications. It is an ideal solution for IoT applications.

ESP32-CAM adopts DIP package and can be directly inserted into the backplane to realize rapid production of products, providing customers with high-reliability connection mode, which is convenient for application in various IoT hardware terminals.

The ESP32-CAM Development Board with camera doesn’t come with a USB connector, so you need an USB to TTL/Serial adaptor/converter to upload code through the  serial pins (U0R and U0T pins).

Features:

  • The smallest 802.11b/g/n Wi-Fi BT SoC Module
  • Low power 32-bit CPU,can also serve the application processor
  • Up to 160MHz clock speed,Summary computing power up to 600 DMIPS
  • Built-in 520 KB SRAM, external 4MPSRAM
  • Supports UART/SPI/I2C/PWM/ADC/DAC
  • Support OV2640 and OV7670 cameras,Built-in Flash lamp.
  • Support image WiFI upload
  • Support TF card
  • Supports multiple sleep modes.
  • Embedded Lwip and FreeRTOS
  • Supports STA/AP/STA+AP operation mode
  • Support Smart Config/AirKiss technology
  • Support for serial port local and remote firmware upgrades (FOTA)

Specifications:

  • Dimensions 40.5mm x27mm x4.5mm
  • Weight G.W 20g
  • Battery Exclude
  • Package DIP-16
  • SPI Flash Default 32Mbit
  • RAM 520KB SRAM +4M PSRAM
  • Bluetooth Bluetooth 4.2 BR/EDR and BLE standards
  • Wi-Fi 802.11 b/g/n/
  • Support interface UART,SPI,I2C,PWM
  • Support TF card Maximum support 4G
  • IO port 9
  • UART Baudrate Default 115200 bps
  • Image Output Format JPEG( OV2640 support only ), BMP,GRAYSCALE
  • Spectrum Range 2412 ~2484MHz
  • Antenna Onboard PCB antenna, gain 2dBi
  • Transmit Power 802.11b: 17±2 dBm (@11Mbps); 802.11g: 14±2 dBm (@54Mbps); 802.11n: 13±2 dBm (@MCS7)
  • Receiving Sensitivity CCK, 1 Mbps : -90dBm; CCK, 11 Mbps: -85dBm; 6 Mbps (1/2 BPSK): -88dBm; 54 Mbps (3/4 64-QAM): -70dBm; MCS7 (65 Mbps, 72.2 Mbps): -67dBm
  • Power Dissipation Turn off the flash lamp:180mA@5V; Turn on the  flash lamp and turn on the brightness to the maximum:310mA@5V; Deep-sleep: Minimum power consumption can be achieved 6mA@5V; Moderm-sleep: Minimum up to 20mA@5V; Light-sleep: Minimum up to 6.7mA@5V
  • Security WPA/WPA2/WPA2-Enterprise/WPS
  • Power Supply Range 5V
  • Operating Temperature -20 ℃ ~ 85 ℃
  • Storage Environment -40 ℃ ~ 90 ℃ , < 90%RH

In the package you will get 1 x ESP32-CAM Development Board, 1x camera Module-OV2640-FPC-24P-0.5mm-21mm- 2 Megapixel and 2x headers-2.54mm-1x8pin.  

On-Board vs IPEX Antenna

ESP32-CAM Development Board with camera can be with the antenna jumper set for an external antenna or for the on-board antenna. You can see the two different settings below:

If you have a low frame rate or poor reception this might be the problem. You can either move the jumper with a bit of very careful soldering or buy an IPEX WiFi antenna which will improve the signal.

Applications:

  • We can easily build a simple camera with this board and save the photos in an SD card using the embedded SD card slot the board offers.
  • We can then modify this project to detect humans and save an image when one is detected.
  • We can recognize human faces and act accordingly.
  • We can build a surveillance camera with the ESP32 Cam board.
  • We can also stream video using this board.

You can find the ESP32-CAM schematic here, ESP32-CAM development board specification is here, camera specification is here.

Signals and connections of the ESP32-CAM Development Board with camera

ESP32-CAM pinout:

You can read more about ESP32-CAM GPIOs here.

Wiring

ESP32-CAM module    FTDI programmer

U0TXD (GPIO 1)          RXI                   

U0RXD (GPIO 3)         TX0

GND                          GND

5V                             5V

Connect GND and GPIO0 – just for flashing. Many FTDI programmers have a jumper that allows you to select between 3.3V or 5V. Make sure the jumper is on 5V.   

ESP32CAM HOW TO UPLOAD

Please note: the order of the FTDI programmer’s pins on the diagram may not match yours. Make sure you check label next to each pin on ESP32-CAM development board.

Step by Step instruction

1. Adding ESP32 platform to Arduino IDE

To program the ESP32-CAM development board with Arduino IDE, you need to have Arduino IDE installed as well as the ESP32 add-on.

If you previously installed the hardware libraries for the ESP32 using the old method you need to delete them. Find the folder where your Arduino libraries are kept by opening File -> Preferences in the Arduino IDE. See the sketchbook location field. Click on Browse button. Inside Arduino folder open the hardware folder and find and delete either the esp32 folder or espressif folder.

We are using PC with Windows 7 OS.

1.Download and install the latest Arduino IDE version Windows Installer. You can download it here.

2.Open Arduino IDE. 

3.Open the Preferences window from the Arduino IDE. Go to File -> Preferences.

4.Paste the following line into the Additional Boards Manager URLs fieldhttps://dl.espressif.com/dl/package_esp32_index.json

5.If you have entries in this field already then add the new line before them but separate them with a comma.

6.Go to Tools -> Board -> Board Manager…

7. Type ESP32, point with mouse cursor on record line found (ESP32 by …) and click on Install button to install the new hardware libraries.

8.When installation done, close and open your Arduino IDE again.

9.You will be able to find all the ESP32 boards in the Arduino IDE’s board selector.

2. Uploading the sketch to the ESP32-CAM Development Board with camera using FTDI programmer

1. Most SD cards work right out of the box, but it’s possible you have one that was used in a computer or camera and it cannot be read by the SD library. It’s not desirable to format SD cards frequently, as it shortens their life span. You’ll need a SD reader and computer to format your card. The library supports the FAT16 and FAT32 filesystems, but use FAT16 when possible. See additional info here. Please note that according to the ESP32-CAM development board specifications, the ESP32-CAM should only support 4 GB SD cards. However, we have tested it with 16 GB SD card and it works very well.

2.Format the SD card as FAT16 or FAT32. Insert the SD card adapter with Micro SD card in your PC. Go to My Computer and right click on the SD card. Select Format…

3.A new window pops up. Select FAT32, press Start to initialize the formatting process and follow the onscreen instructions.

4. Click on Close button when done. Take out and insert the formatted Mirco SD card to TF card slot in ESP32-CAM.

5.Do wiring. Very important: GPIO 0 (IO 0) must be connected to GND otherwise you will not be able to upload code. We use the AI-THINKER ESP32-CAM Development Board.

6.Attach WiFi antenna (optional). It will help you to increase WiFi range.

7.Attach OV2640 camera.

8. Plug your FTDI programmer into your PC USB port.

9. Open Arduino IDE. Open the sketch. Change the OV2640 camera settings in the code to adjust the image.

10. Go to Tools -> Board, select AI Thinker ESP32-CAM.

esp32-cam how to upload

11. Go to Tools -> Port and select the COM port the ESP32-CAM Development Board connected to (we have COM7).

esp32-cam how to upload

12. Click on Upload button in your Arduino IDE.

13.When you see some dots in the debugging window, press the ESP32-CAM Development Board on-board RST (RESET) button to restart your ESP32 in flashing mode.

esp32-cam how to upload code

14. After a few seconds, the code should be successfully uploaded to your board. When you see the “Done uploading” message, you need to remove GPIO0 from GND and press the ESP32-CAM Development Board on-board RST (RESET) button to run your new code.

esp32 cam settings

15. It will start taking picture every 10 seconds and save it in the microSD card.

esp32-cam settings

16. When you check the pictures on microSD card you will find the best settings for your condition. See below several images taken with different settings:

1.ESP32-CAM picture with grayscale effect enabled

esp32-cam settings

2.ESP32-CAM picture with brightness set to 2

esp32-cam settings

3.ESP32-CAM picture with contrast set to 2 and saturation to -2

esp32-cam settings

4.ESP32-CAM Photo with Default Settings

esp32-cam settings
esp32-cam settings

How to adjust the image settings

Changing the camera settings is quite easy. You just need to use the lines of code after initializing the camera. After that, you can use the usual functions and code to control the camera. To change the image settings, after initializing the camera, use the following lines:

sensor_t * s = esp_camera_sensor_get()

s->set_brightness(s, 0); // -2 to 2
s->set_contrast(s, 0); // -2 to 2
s->set_saturation(s, 0); // -2 to 2
s->set_special_effect(s, 0); // 0 to 6 (0 – No Effect, 1 – Negative, 2 – Grayscale, 3 – Red Tint, 4 – Green Tint, 5 – Blue Tint, 6 – Sepia)
s->set_whitebal(s, 1); // 0 = disable , 1 = enable
s->set_awb_gain(s, 1); // 0 = disable , 1 = enable
s->set_wb_mode(s, 0); // 0 to 4 – if awb_gain enabled (0 – Auto, 1 – Sunny, 2 – Cloudy, 3 – Office, 4 – Home)
s->set_exposure_ctrl(s, 1); // 0 = disable , 1 = enable
s->set_aec2(s, 0); // 0 = disable , 1 = enable
s->set_ae_level(s, 0); // -2 to 2
s->set_aec_value(s, 300); // 0 to 1200
s->set_gain_ctrl(s, 1); // 0 = disable , 1 = enable
s->set_agc_gain(s, 0); // 0 to 30
s->set_gainceiling(s, (gainceiling_t)0); // 0 to 6
s->set_bpc(s, 0); // 0 = disable , 1 = enable
s->set_wpc(s, 1); // 0 = disable , 1 = enable
s->set_raw_gma(s, 1); // 0 = disable , 1 = enable
s->set_lenc(s, 1); // 0 = disable , 1 = enable
s->set_hmirror(s, 0); // 0 = disable , 1 = enable
s->set_vflip(s, 0); // 0 = disable , 1 = enable
s->set_dcw(s, 1); // 0 = disable , 1 = enable
s->set_colorbar(s, 0); // 0 = disable , 1 = enable

The following table shows each function and the values accepted:

FunctionMeaningValues
set_brightness()Set brightness-2 to 2
set_contrast()Set contrast-2 to 2
set_saturation()Set saturation-2 to 2
set_special_effect()Set a special effect0 – No Effect
1 – Negative
2 – Grayscale
3 – Red Tint
4 – Green Tint
5 – Blue Tint
6 – Sepia
set_whitebal()Set white balance0 – disable
1 – enable
set_awb_gain()Set white balance gain0 – disable
1 – enable
set_wb_mode()Set white balance mode0 – Auto
1 – Sunny
2 – Cloudy
3 – Office
4 – Home
set_exposure_ctrl()Set exposure control0 – disable
1 – enable
set_aec2()0 – disable
1 – enable
set_ae_level()-2 to 2
set_aec_value()0 to 1200
set_gain_ctrl()0 – disable
1 – enable
set_agc_gain()0 to 30
set_gainceiling()0 to 6
set_bpc()0 – disable
1 – enable
set_wpc()0 – disable
1 – enable
set_raw_gma()0 – disable
1 – enable
set_lenc()Set lens correction0 – disable
1 – enable
set_hmirror()Horizontal mirror0 – disable
1 – enable
set_vflip()Vertical flip0 – disable
1 – enable
set_dcw()0 – disable
1 – enable
set_colorbar()Set a colorbar0 – disable
1 – enable

All functions in the table appear in the same order as in our project Basics: Project 084a ESP32-CAM Development Board with camera – Camera Web Server with Arduino IDE example, so that it is very easy to identify which functions and values you will need to use to get a better image in your case.

Code

We are using the simple example to show how to apply the image settings in the code. The simple example takes a picture every 10 seconds and saves it in the microSD card. There is a section in the code that allows you to change the camera settings.

To makes things easy, we have created a function called configCamera() that contains all the commands to initialize the OV2640 camera. First, we assign the OV2640 GPIOs. Then we set the camera frequency config.xclk_freq_hz and the image format config.pixel_format. The image format can be PIXFORMAT_YUV422 or PIXFORMAT_GRAYSCALE or PIXFORMAT_RGB565 or PIXFORMAT_JPEG. Then,we set the frame size, jpeg quality and framebuffer count. We select different settings depending if a camera with PSRAM or without PSRAM. The frame size can be:

  • FRAMESIZE_UXGA (1600 x 1200)
  • FRAMESIZE_QVGA (320 x 240)
  • FRAMESIZE_CIF (352 x 288)
  • FRAMESIZE_VGA (640 x 480)
  • FRAMESIZE_SVGA (800 x 600)
  • FRAMESIZE_XGA (1024 x 768)
  • FRAMESIZE_SXGA (1280 x 1024)

The image quality (jpeg_quality) can be a number between 0 and 63. A lower number means a higher quality. But very low numbers for image quality, especially at higher resolution can force the ESP32-CAM development board to crash or it may not be able to take the pictures properly. So, if you notice that the pictures taken with the ESP32-CAM development board are cut in half, or with strange colors, it is a sign that you need to bring down the quality (make a higher number). Then we initialize OV2640 camera. You can add the lines of code we have shown previously to change the image settings – brightness, contrast, saturation, white balance, exposure, and so on. The values shown below are default values, so you can change them to adjust the image settings.

Troubleshooting

If you have any errors with your ESP32-CAM development board please check our project – Basics: Project 084d ESP32-CAM Development Board with camera – Troubleshooting

Summary

We have learnt in this project how to adjust the ESP32-CAM Development Board OV2640 camera settings such as contrast, brightness, resolution, quality, saturation and so on using Arduino IDE.

This can be very useful as, depending on where you place your ESP32-CAM development board, maybe you will need to adjust the settings to get a better image.

Thank you for reading and supporting us.

Libraries:

  • None

Project resources:

  • See attachments on the beginning of this project description

AcoptexCom

Leave a Reply

Your email address will not be published.