Real-time Display of Camera Captured Images with ESP32-S3 (Based on MicroPython)

Real-time Display of Camera Captured Images with ESP32-S3 (Based on MicroPython)

Click the blue text above to follow us

Previously, we used OV2640 to capture high-definition photos (ESP32-S3 captures 1600X1200 resolution photos) and displayed JPG images on an LCD driven by ST7789 (ESP32-S3 displays JPG and PNG images on LCD (based on MicroPython)). Now we combine the two to allow the LCD to display the images captured by the OV2640 camera in real-time, achieving functionality similar to a camera or camcorder.

1. Required Hardware

This time we introduce an ESP32-S3-EYE development board gifted by a friend, the photo is as follows:
Real-time Display of Camera Captured Images with ESP32-S3 (Based on MicroPython)
Real-time Display of Camera Captured Images with ESP32-S3 (Based on MicroPython)
This ESP32-S3-EYE development board is a bit different from the official board from Espressif, but the functions are generally the same. It integrates an OV2640 camera on the front, an SD card, and on the back, there is a 240X240 LCD screen and 6 buttons. It can be made into a card camera-like device, displaying the camera’s captured images in real-time on the LCD, and storing the captured photos on the SD card using the buttons.

2. Test Code

First, initialize the LCD screen; the LCD uses SPI drive, the code is as follows:
spi=SPI(1,baudrate=30000000, sck=Pin(21), mosi=Pin(47))# Use hardware SPI, speed cannot be too high, too high will cause CPU to restart, actual measurement above 30000000 will restart
tft=st7789.ST7789(spi, 320, 240, dc=Pin(43, Pin.OUT), cs=Pin(44, Pin.OUT),inversion=True)
tft.init()
tft.rotation(0)
tft.fill(0)
Then, initialize the OV2640 camera; note to use camera.deinit() to release the camera in time, the code is as follows:
camera.deinit()
try:    camera.init(0, d0=11, d1=9, d2=8, d3=10, d4=12, d5=18, d6=17, d7=16,
            format=camera.JPEG, framesize=camera.FRAME_HQVGA, fb_location=camera.PSRAM,
            xclk_freq=camera.XCLK_10MHz,
            href=7, vsync=6, reset=-1, pwdn=-1,
            sioc=5, siod=4, xclk=15, pclk=13)
except Exception as e:    camera.deinit()
    camera.init(0, d0=11, d1=9, d2=8, d3=10, d4=12, d5=18, d6=17, d7=16,
            format=camera.JPEG, framesize=camera.FRAME_HQVGA, fb_location=camera.PSRAM,
            xclk_freq=camera.XCLK_10MHz,
            href=7, vsync=6, reset=-1, pwdn=-1,
            sioc=5, siod=4, xclk=15, pclk=13)

Finally, through the while True loop, the images captured by the camera are displayed in real-time on the LCD screen. The complete code is as follows:

from machine import SPI,Pin,PWM,SoftSPI
import time,camera,st7789 

spi=SPI(1,baudrate=30000000, sck=Pin(21), mosi=Pin(47))# Use hardware SPI, speed cannot be too high, too high will cause CPU to restart, actual measurement above 30000000 will restart
tft=st7789.ST7789(spi, 320, 240, dc=Pin(43, Pin.OUT), cs=Pin(44, Pin.OUT),inversion=True)
tft.init()
tft.rotation(0)
tft.fill(0)
camera.deinit()
try:    camera.init(0, d0=11, d1=9, d2=8, d3=10, d4=12, d5=18, d6=17, d7=16,
            format=camera.JPEG, framesize=camera.FRAME_HQVGA, fb_location=camera.PSRAM,
            xclk_freq=camera.XCLK_10MHz,
            href=7, vsync=6, reset=-1, pwdn=-1,
            sioc=5, siod=4, xclk=15, pclk=13)
except Exception as e:    camera.deinit()
    camera.init(0, d0=11, d1=9, d2=8, d3=10, d4=12, d5=18, d6=17, d7=16,
            format=camera.JPEG, framesize=camera.FRAME_HQVGA, fb_location=camera.PSRAM,
            xclk_freq=camera.XCLK_10MHz,
            href=7, vsync=6, reset=-1, pwdn=-1,
            sioc=5, siod=4, xclk=15, pclk=13)
while True:        buf=camera.capture()
    with open('/1.jpg','wb') as f:        f.write(buf)
    tft.jpg('/1.jpg', 0, 0)

3. Test Results

Video effect:
Real-time Display of Camera Captured Images with ESP32-S3 (Based on MicroPython)

01

ESP32-S3 displays JPG and PNG images on LCD (based on MicroPython)

02

ESP32-S3 captures photos with a resolution of 1600X1200

03

ESP32-S3 implements web image transmission (based on MicroPython)

Leave a Comment

×