Corrupted image file with esp32-s3 and OV5640 module

amisbs
Posts: 2
Joined: Tue Jul 04, 2023 3:31 pm

Corrupted image file with esp32-s3 and OV5640 module

Postby amisbs » Tue Jul 04, 2023 3:51 pm

We have been working with the ESP32-S3 dev module (ESP32-S3-WROOM-1-N8R8) in order to capture 5 megapixel images with the Arducam OV5640D (which essentially is, to our understanding, a breakout board with voltage dividers for the OV5640 camera module)
When setting the resolution to HQVGA (240x176) we get the following output:
  1. ESP-ROM:esp32s3-20210327
  2. Build:Mar 27 2021
  3. rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
  4. SPIWP:0xee
  5. mode:DIO, clock div:1
  6. load:0x3fce3808,len:0x44c
  7. load:0x403c9700,len:0xbe4
  8. load:0x403cc700,len:0x2a38
  9. entry 0x403c98d4
  10. [   115][I][esp32-hal-psram.c:96] psramInit(): PSRAM enabled
  11. [   129][D][esp32-s3-minimal-ov5640-test.ino:18] printDebugMemoryInfo(): Total heap: 388856
  12. [   129][D][esp32-s3-minimal-ov5640-test.ino:19] printDebugMemoryInfo(): Free heap: 363272
  13. [   134][D][esp32-s3-minimal-ov5640-test.ino:20] printDebugMemoryInfo(): Total PSRAM: 8386295
  14. [   142][D][esp32-s3-minimal-ov5640-test.ino:21] printDebugMemoryInfo(): Free PSRAM: 8386295
  15. [  1057][I][camera_functions.ino:84] camera_capture(): [camera_functions.ino] Picture taken! Its size was: 1452 bytes
  16. FFD8FFE000104A46494600010101000000000000FFDB0043000C08090B09080 ... 00A2800A2800A2800A2800A2800A2800A2800A2800A2800A2800A2800A2800A2803FFFD9
Sometimes the printed bytes correspond to a broken jpeg file, otherwise it is either corrupted or valid.

When setting the resolution to FRAMESIZE_QSXGA 2560x1920 we get "camera capture failed error", despite PSRAM being enabled and abundant.

Here is the arduino config:
arduino_setup.png
arduino_setup.png (67.31 KiB) Viewed 1270 times

Here is the arduino code:

main file
  1. #include "esp_camera.h"
  2.  
  3. void setup()
  4. {
  5.   Serial.begin(115200);
  6.   printDebugMemoryInfo();
  7.   camera_init();
  8. }
  9.  
  10. void loop()
  11. {  
  12.   camera_capture();
  13.   delay(5000);
  14. }
  15.  
  16. void printDebugMemoryInfo()
  17. {
  18.   log_d("Total heap: %d", ESP.getHeapSize());
  19.   log_d("Free heap: %d", ESP.getFreeHeap());
  20.   log_d("Total PSRAM: %d", ESP.getPsramSize());
  21.   log_d("Free PSRAM: %d", ESP.getFreePsram());
  22. }
and the camera_functions.ino:
  1. #include "esp_camera.h"
  2.  
  3. #define CAM_MODULE_NAME "Arducam OV5640D"
  4. #define CAM_PIN_PWDN -1
  5. #define CAM_PIN_RESET -1
  6.  
  7. #define CAM_PIN_VSYNC 12
  8. #define CAM_PIN_HREF 11
  9. #define CAM_PIN_PCLK 10
  10. #define CAM_PIN_XCLK 9
  11.  
  12. #define XCLK_FREQ_HZ 20000000
  13.  
  14. #define CAM_PIN_SIOD 13 //sda
  15. #define CAM_PIN_SIOC 8 //scl
  16.  
  17. #define CAM_PIN_D0 4
  18. #define CAM_PIN_D1 5
  19. #define CAM_PIN_D2 6
  20. #define CAM_PIN_D3 7
  21. #define CAM_PIN_D4 15
  22. #define CAM_PIN_D5 16
  23. #define CAM_PIN_D6 17
  24. #define CAM_PIN_D7 18
  25.  
  26. static const char* TAG = "camera_functions.ino";
  27.  
  28. static camera_config_t camera_config = {  
  29.   .pin_pwdn = CAM_PIN_PWDN,
  30.   .pin_reset = CAM_PIN_RESET,
  31.   .pin_xclk = CAM_PIN_XCLK,
  32.   .pin_sscb_sda = CAM_PIN_SIOD,
  33.   .pin_sscb_scl = CAM_PIN_SIOC,
  34.  
  35.   .pin_d7 = CAM_PIN_D7,
  36.   .pin_d6 = CAM_PIN_D6,
  37.   .pin_d5 = CAM_PIN_D5,
  38.   .pin_d4 = CAM_PIN_D4,
  39.   .pin_d3 = CAM_PIN_D3,
  40.   .pin_d2 = CAM_PIN_D2,
  41.   .pin_d1 = CAM_PIN_D1,
  42.   .pin_d0 = CAM_PIN_D0,
  43.   .pin_vsync = CAM_PIN_VSYNC,
  44.   .pin_href = CAM_PIN_HREF,
  45.   .pin_pclk = CAM_PIN_PCLK,
  46.  
  47.   .xclk_freq_hz = XCLK_FREQ_HZ,
  48.   .ledc_timer = LEDC_TIMER_0,
  49.   .ledc_channel = LEDC_CHANNEL_0,
  50.  
  51.   .pixel_format = PIXFORMAT_JPEG,
  52.   .frame_size = FRAMESIZE_HQVGA, //240x176
  53.   .jpeg_quality = 12,
  54.   .fb_count = 1,
  55.   .grab_mode = CAMERA_GRAB_LATEST//CAMERA_GRAB_WHEN_EMPTY
  56. };
  57.  
  58. esp_err_t camera_init(){
  59.   //power up the camera if PWDN pin is defined
  60.   if(CAM_PIN_PWDN != -1){
  61.     pinMode(CAM_PIN_PWDN, OUTPUT);
  62.     digitalWrite(CAM_PIN_PWDN, LOW);
  63.   }
  64.  
  65.   //initialize the camera
  66.   esp_err_t err = esp_camera_init(&camera_config);
  67.   if (err != ESP_OK) {
  68.     ESP_LOGE(TAG, "Camera Init Failed");
  69.     return err;
  70.   }
  71.  
  72.   return ESP_OK;
  73. }
  74.  
  75. esp_err_t camera_capture(){
  76.   //acquire a frame
  77.   camera_fb_t * fb = esp_camera_fb_get();
  78.   if (!fb) {
  79.     ESP_LOGE(TAG, "Camera Capture Failed");
  80.     return ESP_FAIL;
  81.   }
  82.    
  83.   ESP_LOGI(TAG, "Picture taken! Its size was: %zu bytes", fb->len);
  84.   for (int i=0; i<fb->len; i++) {
  85.     if (fb->buf[i] < 16) {
  86.       Serial.print('0');
  87.     }
  88.     Serial.print(fb->buf[i], HEX);
  89.   }
  90.   Serial.println();
  91.  
  92.   //return the frame buffer back to the driver for reuse
  93.   esp_camera_fb_return(fb);
  94.   return ESP_OK;
  95. }
  96.  

amisbs
Posts: 2
Joined: Tue Jul 04, 2023 3:31 pm

Re: Corrupted image file with esp32-s3 and OV5640 module

Postby amisbs » Thu Jul 06, 2023 9:18 am

Upon further testing, we have discovered that even with the higher resolution the behaviour is similar, with the output being either "camera capture failed" or a sequence of bytes containing valid jpg markers (FF D8 FF at the beginning and FF D9 at the end) that amount to an invalid image file.

simardeep27
Posts: 1
Joined: Thu Mar 14, 2024 7:39 am

Re: Corrupted image file with esp32-s3 and OV5640 module

Postby simardeep27 » Thu Mar 14, 2024 7:42 am

Hi, can you please share your pin configuration to show how are you connecting your camera with the esp32 module. I am trying to connect a arducam 2MP plus camera to the same, but I am not able to read the frames.

Thanks

Who is online

Users browsing this forum: No registered users and 62 guests