General

ESP32S3 SD Card

userHead JR05 2025-04-27 21:39:01 759 Views4 Replies

I am using esp32s3 board . Anyone tried to access sd card slot in the board ?

2025-05-25 01:12:02

#include "esp_camera.h"

#include "FS.h"

#include "SD.h"

#include "SPI.h"


 

// === Camera-Pin-Configuration ===

#define PWDN_GPIO_NUM     -1

#define RESET_GPIO_NUM    -1

#define XCLK_GPIO_NUM     5

#define Y9_GPIO_NUM       4

#define Y8_GPIO_NUM       6

#define Y7_GPIO_NUM       7

#define Y6_GPIO_NUM       14

#define Y5_GPIO_NUM       17

#define Y4_GPIO_NUM       21

#define Y3_GPIO_NUM       18

#define Y2_GPIO_NUM       16

#define VSYNC_GPIO_NUM    1

#define HREF_GPIO_NUM     2

#define PCLK_GPIO_NUM     15

#define SIOD_GPIO_NUM     8

#define SIOC_GPIO_NUM     9


 

// === SD-Card ===

#define SD_MOSI 11

#define SD_MISO 13

#define SD_SCK  12

#define SD_CS   10


 

SPIClass spi = SPIClass(HSPI); // HSPI for SD-Card


 

void setup() {

  Serial.begin(115200);

  Serial.println("Start System...");


 

  // Init camera

  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;

  config.frame_size = FRAMESIZE_SVGA;

  config.jpeg_quality = 12;

  config.fb_count = 1;


 

  if (psramFound()) {

    config.fb_count = 2;

    config.grab_mode = CAMERA_GRAB_LATEST;

  }


 

  if (esp_camera_init(&config) != ESP_OK) {

    Serial.println("Error Init Camera!");

    return;

  }

  Serial.println("Camera ready.");


 

  // Init SD-Card

  spi.begin(SD_SCK, SD_MISO, SD_MOSI, SD_CS);

  if (!SD.begin(SD_CS, spi)) {

    Serial.println("Error on Init SD-Card!");

    return;

  }

  Serial.println("SD-Card ready.");


 

  // Wait 30 Seconds

  Serial.println("Wait 30 Seconds...");

  delay(30000);


 

  // Zeitstempel (mit millis() oder RTC)

  unsigned long now = millis();

  int ms = now % 1000;

  int sec = (now / 1000) % 60;

  int min = (now / (1000 * 60)) % 60;

  int hour = (now / (1000 * 60 * 60)) % 24;

  int day = 1;

  int month = 1;

  int year = 2025;


 

  char filename[32];

  snprintf(filename, sizeof(filename), "/%04d%02d%02d_%02d%02d%02d%03d.jpg",

           year, month, day, hour, min, sec, ms);


 

  // Take Picture

  Serial.println("Take Picture...");

  camera_fb_t *fb = esp_camera_fb_get();

  if (!fb) {

    Serial.println("Error on take picture!");

    return;

  }


 

  // Save Picture on SD-Card

  File file = SD.open(filename, FILE_WRITE);

  if (!file) {

    Serial.println("Error on save picture on SD-Card!");

  } else {

    file.write(fb->buf, fb->len);

    file.close();

    Serial.print("Saved Picture as: ");

    Serial.println(filename);

  }


 

  esp_camera_fb_return(fb);

  Serial.println("Process done.");

}


 

void loop() {

  // Nothing to do

}


 

userHeadPic Lupin
2025-04-28 02:55:30

Did you check this video?

userHeadPic ahsrab.rifat
2025-04-27 21:43:09

I am using this board 

https://wiki.dfrobot.com/SKU_DFR1154_ESP32_S3_AI_CAM#target_9

userHeadPic JR05
ahsrab.rifat wrote:

Though your board is different, you can get help from this: https://dronebotworkshop.com/esp32-cam-microsd/

2025-04-28 19:54:48
1 Replies