Skip to content
OV-2640: ESP32 Digital Camera

icon picker
OV-2640 ESP32 Setup Guide (Advanced)

Important: This guide is for setting up the bare module on a breadboard. Visit this link for setup using the ESP32-CAM System on Chip Module (recommended): ​
This is much easier and more repeatable than the steps below which set up the module over pins.

Interfacing with OV-2640 Camera over CSI using ESP32 Microcontroller


Hardware Requirements
ESP32 microcontroller (e.g., ESP32 DevKitC)
OV-2640 camera module
CSI cable (or a compatible camera cable)
Breadboard and jumper wires

Software Requirements
ESP32 Arduino core (install via Arduino IDE)
ESP32-CAM library (install via Arduino Library Manager)

Connecting the Hardware

Connect the OV-2640 camera module to the ESP32 microcontroller using the CSI cable. Make sure to match the pinouts:
OV-2640 VCC to ESP32 3V3
OV-2640 GND to ESP32 GND
OV-2640 SCL to ESP32 SCL (GPIO22)
OV-2640 SDA to ESP32 SDA (GPIO21)
OV-2640 PCLK to ESP32 PCLK (GPIO0)
OV-2640 VSYNC to ESP32 VSYNC (GPIO25)
OV-2640 HREF to ESP32 HREF (GPIO26)
Connect the ESP32 microcontroller to your computer using a USB cable.
In the Arduino IDE, take note of which serial port becomes active when the device is connected. It is this port that we will use for flashing and debugging the microcontroller.

Installing the ESP32-CAM Library

Open the Arduino IDE and navigate to Sketch > Include Library > Manage Libraries.
Search for "ESP32-CAM” and install the library.
Restart the Arduino IDE.

Example Code
Create a new Arduino project and paste the following code:

#include "esp_camera.h"

// Pin definitions
#define PWDN_GPIO_NUM -1
#define RESET_GPIO_NUM -1
#define XCLK_GPIO_NUM 0
#define SIOD_GPIO_NUM 26
#define SIOC_GPIO_NUM 27
#define Y9_GPIO_NUM 35
#define Y8_GPIO_NUM 34
#define Y7_GPIO_NUM 39
#define Y6_GPIO_NUM 36
#define Y5_GPIO_NUM 21
#define Y4_GPIO_NUM 19
#define Y3_GPIO_NUM 18
#define Y2_GPIO_NUM 5
#define VSYNC_GPIO_NUM 25
#define HREF_GPIO_NUM 23
#define PCLK_GPIO_NUM 22

// Camera settings
#define CAMERA_MODEL OV2640

void setup() {
Serial.begin(115200);

// Initialize the camera
camera_config_t config;
config.ledc_channel = LEDC_CHANNEL_0;
config.ledc_timer = LEDC_TIMER_0;
config.pin_d0 = Y2_GPIO_NUM;
config.pin_d1 = Y3_GPIO_NUM;
config.pin_d2 = Y4_GPIO_NUM;
config.pin_d3 = Y5_GPIO_NUM;
config.pin_d4 = Y6_GPIO_NUM;
config.pin_d5 = Y7_GPIO_NUM;
config.pin_d6 = Y8_GPIO_NUM;
config.pin_d7 = Y9_GPIO_NUM;
config.pin_xclk = XCLK_GPIO_NUM;
config.pin_pclk = PCLK_GPIO_NUM;
config.pin_vsync = VSYNC_GPIO_NUM;
config.pin_href = HREF_GPIO_NUM;
config.pin_sscb_sda = SIOD_GPIO_NUM;
config.pin_sscb_scl = SIOC_GPIO_NUM;
config.pin_pwdn = PWDN_GPIO_NUM;
config.pin_reset = RESET_GPIO_NUM;
config.xclk_freq_hz = 20000000;
config.pixel_format = PIXFORMAT_JPEG;
config.frame_size = FRAMESIZE_UXGA;
config.jpeg_quality = 12;
config.fb_count = 1;

esp_camera_init(&config);
}

void loop() {
// Capture a frame
camera_fb_t *fb = esp_camera_fb_get();
if (!fb) {
Serial.println("Camera capture failed");
return;
}

// Print the frame buffer size
Serial.println("Frame buffer size: " + String(fb->len));

// Release the frame buffer
esp_camera_fb_return(fb);

delay(1000);
}

Uploading the Code
Select the ESP32 DevKitC board, or whichever module you are programming, in the Arduino IDE.
Choose the correct serial port.
Upload the code to the ESP32 microcontroller.

Verifying the Camera
Open the Serial Monitor in the Arduino IDE.
Set the baud rate to 115200.
You should see the frame buffer size printed every second.

Conclusion
In this tutorial, we have successfully interfaced the OV-2640 camera with an ESP32 microcontroller using the CSI protocol. We have also captured and printed the frame buffer size using the ESP32-CAM library. You can now use this setup as a starting point for your own projects, such as image processing, object detection, or video streaming.

References


Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.