5inch_P4_IDF_13_Camera_Real_Time: ESP32-P4 Camera Real-Time Display¶
1. Course Introduction¶
This lesson initializes the camera and displays the real-time video feed on the 5-inch LCD. The program first completes the I2C, STC8, backlight, and display initialization, then calls camera_video_init() and camera_work() to start the video pipeline; after waiting 300 ms, it calls set_camera_img_display(true) within the LVGL lock to display the image.
2. Learning Objectives¶
- Understand the sequencing relationship among camera initialization, the video worker node, and LCD display.
- Be able to explain why execution must stop when
camera_work()returns-1. - Master how to toggle the camera image display state under LVGL lock protection.
- Be able to determine whether the video link is established based on whether a real-time image appears on the screen.
3. Prerequisites¶
- Applicable development board: CrowPanel Advanced 5-inch ESP32-P4 HMI AI Display Development Board.
- Software: VS Code, ESP-IDF Extension (ESP-IDF v5.5.4 or later).
- Project dependencies: keep the
main/main.c,peripheral/bsp_camera, andperipheral/bsp_illuminatecomponents, along with theesp_lvgl_port,lvgl,esp_video_init, andesp_cam_sensormanaged components. - Configuration: target chip
esp32p4;
Code download link:
4. Software Operation Steps¶
Open the ESP-IDF Extension panel in VS Code, click Open ESP-IDF Project, and select the Lesson13-Camera_Real-Time folder.
You can also drag this project folder directly into VS Code.
First select the ESP-IDF v5.5.4 toolchain, set the flashing method to UART, and then select the serial port that corresponds to the actual development board. Next, click Set Espressif Device Target in the ESP-IDF Extension panel and select esp32p4. After the setup is complete, the status bar should display ESP-IDF v5.5.4, UART, the required COM port, and ESP32-P4.
Click SDK Configuration Editor in the bottom status bar of VS Code or in the ESP-IDF extension panel, and wait until the configuration page is fully loaded before modifying parameters. If the page is still loading, do not run Build immediately.
Enter flash in the search box and ensure that Flash SPI mode is QIO; Flash Sampling Mode is STR Mode; Flash SPI speed is 80 MHz; and Flash size is 16 MB. These parameters should match the onboard Flash of the Advance-P4.
Next, refer to "4. Software Operation Steps" in
Lesson07_Turn_on_the_Screento complete the detailed SDK configuration; the related configuration methods were covered in Lesson 7.
Configure the camera-related options as shown in the figure to ensure the camera works properly.
Carefully verify all parameters item by item. Do not check only the options in the red boxes; ensure the current configuration matches the figure.
Use the sensor configuration file sc2336_custom.json provided by the project in the camera component directory. This configuration file contains the parameters required by this camera and must be retained and correctly referenced for the camera image to display properly.
Search for virtual file and set Maximum Number of Virtual Filesystems to 10. This option determines the number of filesystems or device nodes the VFS framework can register simultaneously. This project not only uses V4L2 video device nodes such as /dev/video0, but may also use serial ports, logging, an SD card, or a Flash filesystem; appropriately increasing this value prevents device registration failures, camera open failures, or system instability caused by insufficient VFS slots.
Search for ISP and enable Enable ISP based Video Device and Enable ISP Pipeline Controller as shown in the figure. Once enabled, the system uses the hardware ISP video device driver and creates a dedicated isp_task background task that automatically reads statistics such as exposure and white balance and dynamically adjusts the camera or ISP parameters, thereby achieving more stable and natural color and brightness. This is a key configuration for the ESP32-P4 to achieve high-quality images when using MIPI cameras such as the SC2336.
After verifying that the configuration is correct, click Save in the upper-right corner; confirm that the changes have been saved before executing Build to compile.
Click Full Clean to clear the cache left by the previous compilation. Performing this operation after the first compilation, switching project configurations, or modifying SDK parameters avoids old configurations affecting the new compilation result.
Click Build to compile the project.
Confirm that the development board is connected to the computer via USB, click Select Port to Use to choose the serial port, and click Flash to flash the firmware.
After flashing is complete, click Monitor to open the serial monitor; you should see camera capability query and stream-start logs; press Ctrl + ] to exit the monitor.
After flashing is complete, wait for the device to reset and observe whether the screen displays the camera image in real time.
Finally, you can use the one-click operation button on the ESP-IDF status bar to run compilation, flashing, and opening the serial monitor in sequence. Use this only after the project configuration, serial port, and code have all been verified to be correct; if you need to locate a problem, you should still follow the steps above one by one.
5. Hardware Operation Steps¶
Connect the ESP32-P4 development board to the computer using a USB data cable.
At this point, please remember to connect your Advance-P4 with an additional Type-C cable via the USB 2.0 port.
This is because the maximum current provided by a computer's USB-A port is generally 500mA, and the Advance-P4 requires a sufficient power supply when using multiple peripherals—especially the screen. (It is recommended to connect it to the charger.)
Confirm that the camera FPC cable and the LCD cable are correctly connected.
After flashing is complete and the device resets, observe whether the screen backlight turns on and whether the LCD displays the camera image.
Slowly move the camera or wave your hand in front of the lens, and observe whether the screen image changes synchronously to confirm real-time performance.
Observe whether the image is smooth, free of artifacts or tearing, and with correct, non-tinted colors, to confirm that the CSI capture and display link is stable.
6. Key Code Explanation¶
err = i2c_init();
err = stc8_i2c_init();
err = set_lcd_blight(100);
err = display_init();
err = camera_video_init();
if (err != ESP_OK) init_fail("camera", err);
int video_node = camera_work();
if (video_node == -1) init_fail("camera", ESP_FAIL);
Init() initializes I2C, the STC8 controller, backlight, display/LVGL, and camera resources in the exact order used by the current program. camera_work() starts the video worker and returns its node; -1 is treated as a fatal startup failure.
vTaskDelay(pdMS_TO_TICKS(300));
if (lvgl_port_lock(0)) {
set_camera_img_display(true);
lvgl_port_unlock();
}
After initialization, the application waits 300 ms for camera data. It then acquires the LVGL lock, enables the camera image object with set_camera_img_display(true), and releases the lock so the live frame can be rendered safely.
7. Observed Behavior¶
Upon completion of the startup log, the screen displays the camera's real-time image and outputs The screen is displaying.. If the camera connection, video node, or display initialization fails, the program stops in the error-handling loop and the screen will not display valid video.

















