Skip to content

Camera (MIPI-CSI)

The ESP32-P4 includes a MIPI-CSI receiver interface with an integrated image signal processor (ISP) and H.264 video encoder. This guide covers connecting a camera module and capturing images or video.

SpecificationValue
Interface2-lane MIPI-CSI
Supported sensorOV5647 (5MP)
Maximum usable resolution2MP (1920 x 1080)
ISPIntegrated — auto exposure, white balance, noise reduction
Video encoderH.264, 1080P at 30fps
Connector15-pin FPC (standard Raspberry Pi camera form factor)
  1. Power off the board (disconnect USB).

  2. Locate the MIPI-CSI FPC connector on the board. It uses the standard 15-pin Raspberry Pi camera ribbon cable layout.

  3. Lift the connector latch gently.

  4. Insert the camera ribbon cable with the contacts facing the PCB. The blue backing of the cable should face away from the board.

  5. Press the connector latch down to secure the cable.

  6. Verify the cable is firmly seated and not at an angle.

  7. Reconnect USB power.

  1. Create or open an ESP-IDF project targeting ESP32-P4.

  2. The camera driver is part of the ESP-IDF framework. Configure it via menuconfig:

    Terminal window
    idf.py menuconfig

    Navigate to Component config > Camera Configuration and enable the MIPI-CSI driver.

  3. Initialize the camera in your application:

    #include "esp_camera.h"
    static camera_config_t camera_config = {
    .pin_pwdn = -1,
    .pin_reset = -1,
    .xclk_freq_hz = 20000000,
    .pixel_format = PIXFORMAT_JPEG,
    .frame_size = FRAMESIZE_HD, // 1280x720
    .jpeg_quality = 12,
    .fb_count = 2,
    };
    void app_main(void)
    {
    esp_err_t err = esp_camera_init(&camera_config);
    if (err != ESP_OK) {
    printf("Camera init failed: 0x%x\n", err);
    return;
    }
    camera_fb_t *fb = esp_camera_fb_get();
    if (fb) {
    printf("Captured: %dx%d, %d bytes\n",
    fb->width, fb->height, fb->len);
    esp_camera_fb_return(fb);
    }
    }
  4. Build and flash:

    Terminal window
    idf.py build
    idf.py -p /dev/ttyUSB0 flash monitor

The ESP32-P4’s image signal processor handles common camera processing tasks in hardware, reducing CPU load:

  • Auto Exposure (AE): Adjusts sensor exposure time based on scene brightness.
  • Auto White Balance (AWB): Corrects color cast from different lighting conditions.
  • Noise Reduction: Applies spatial filtering to reduce sensor noise, especially in low-light captures.
  • Demosaicing: Converts Bayer-pattern raw sensor data to RGB.

These features are enabled by default when using the ESP-IDF camera driver. Fine-tuning parameters are available through the ISP configuration API.

The hardware H.264 encoder can produce compressed video streams at up to 1080P 30fps. This is particularly useful for:

  • Streaming video over WiFi 6 to a remote viewer
  • Recording clips to the microSD card
  • Computer vision pre-processing (encode, transmit, decode on a more powerful host)
#include "esp_video_enc.h"
// Configure H.264 encoder
esp_video_enc_config_t enc_config = {
.width = 1920,
.height = 1080,
.fps = 30,
.bitrate = 4000000, // 4 Mbps
};

Computer vision

Capture frames for on-device inference using TensorFlow Lite Micro or edge AI pipelines. The ISP handles preprocessing.

Machine vision

Industrial inspection, barcode/QR scanning, and defect detection at the edge — no cloud dependency.

Video streaming

Stream H.264-encoded video over WiFi 6 for security cameras, baby monitors, or remote inspection.

Time-lapse capture

Periodic image capture stored to microSD, powered by the RTC for accurate scheduling.

SymptomCauseFix
Camera init returns ESP_ERR_NOT_FOUNDRibbon cable not seated properlyReseat the FPC cable, ensure contacts face the PCB
Image is dark or overexposedISP auto-exposure not convergingAllow 1—2 seconds after init before capturing; check lighting
Horizontal lines in imageCSI clock mismatchVerify XCLK frequency matches sensor datasheet (20 MHz for OV5647)
Crash on fb_get()Insufficient PSRAM or framebuffersReduce frame_size or fb_count