Hi everyone
I had designed a board for the ESP32-S3-WROOM-1-N16R8 module (this module has 8MB PSRAM memory and 16MB flash memory) . I wanted the camera OV2640 to capture an image frame with XGA resolution (768*1024) and save it on the SD card. SD Card is also set up with SDIO interface.
.
But the problem is that saved images are very bad. For example, the images are cropped, half of the image is green and the rest of the image is completely black, etc.
.
Camera OV2640 is correctly.
I thought that there might be a problem in saving the images on the SD card, so I also tested the example code camera_webserver in arduino. but still received images by Wifi was corrupted.
.
What could be the problem? For example, Should another option be selected for PSRAM memory? Or is there a problem with the coding?
.
#include "esp_camera.h"
#include "SD_MMC.h"
// Define Camera pins
#define PWDN_GPIO_NUM -1
#define RESET_GPIO_NUM -1
#define XCLK_GPIO_NUM 10
#define SIOD_GPIO_NUM 4
#define SIOC_GPIO_NUM 5
#define Y9_GPIO_NUM 9
#define Y8_GPIO_NUM 11
#define Y7_GPIO_NUM 12
#define Y6_GPIO_NUM 14
#define Y5_GPIO_NUM 47
#define Y4_GPIO_NUM 45
#define Y3_GPIO_NUM 48
#define Y2_GPIO_NUM 21
#define VSYNC_GPIO_NUM 3
#define HREF_GPIO_NUM 46
#define PCLK_GPIO_NUM 13
// Define SDIO pins
#define MMCSCK 16
#define MMCCMD 17
#define MMCD0 15
#define MMCD1 7
#define MMCD2 8
#define MMCD3 18
// Frame settings
#define FRAME_RATE 10 // FPS
#define FRAME_DURATION 1000 / FRAME_RATE // Duration of each frame in milliseconds
unsigned long now;
static unsigned long lastCapture = 0;
static int frameCount = 0;
static File file;
void setup() {
Serial.begin(115200);
// Camera configuration
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_sccb_sda = SIOD_GPIO_NUM;
config.pin_sccb_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;
// Set the resolution frame image
config.frame_size = FRAMESIZE_XGA; //1024x768
config.jpeg_quality = 12;
config.fb_count = 1;
// Use PSRAM for the frame buffer
config.fb_location = CAMERA_FB_IN_PSRAM;
if (psramFound()) {
Serial.println("PSRAM FOUND"); // when run code alwayse PSRAM FOUND.
}
// Initialize the camera
if (esp_camera_init(&config) != ESP_OK) {
Serial.println("Failed to initialize camera.");
return;
}
// Initialize SD card
SD_MMC.setPins(MMCSCK, MMCCMD, MMCD0, MMCD1, MMCD2, MMCD3);
if (!SD_MMC.begin()) {
Serial.println("SD card mount failed.");
return;
}
Serial.println("SD card initialized.");
}
void loop() {
now = millis();
if (now - lastCapture>=FRAME_DURATION) {
lastCapture = now;
// Capture a frame
camera_fb_t *fb = esp_camera_fb_get();
if (!fb) {
Serial.println("Failed to capture image.");
return;
}
// Save frame to SD card
String path = "/frame" + String(frameCount) + ".jpg";
file = SD_MMC.open(path, FILE_WRITE);
if (!file) {
Serial.println("Failed to open file for writing.");
esp_camera_fb_return(fb);
return;
}
file.write(fb->buf, fb->len);
file.close();
esp_camera_fb_return(fb);
frameCount++;
}
// Capture frames for 10 seconds
if (millis() - start_capture >= 10000) {
Serial.println("Capture complete.");
while (true); // Stop the loop
}
}
.