EasyManua.ls Logo

SunFounder ESP32

Default Icon
771 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
SunFounder ESP32 Starter Kit
(continued from previous page)
config.pin_sscb_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;
The camera is then initialized with the configuration, and if it fails, an error message is printed.
esp_err_t err = esp_camera_init(&config);
if (err != ESP_OK) {
Serial.printf("Camera init failed with error 0x%x", err);
return;
}
The SD card is initialized, and if it fails, an error message is printed.
if (!SD_MMC.begin()) {
Serial.println("SD Card Mount Failed");
return;
}
uint8_t cardType = SD_MMC.cardType();
if (cardType == CARD_NONE) {
Serial.println("No SD Card attached");
return;
}
A photo is captured with the camera and stored in the framebuffer.
fb = esp_camera_fb_get();
if (!fb) {
Serial.println("Camera capture failed");
return;
}
The EEPROM is read to retrieve the number of the last picture, then the picture number for the new photo
is incremented.
EEPROM.begin(EEPROM_SIZE);
pictureNumber = EEPROM.read(0) + 1;
A path for the new picture is created on the SD card, with a filename corresponding to the picture number.
String path = "/picture" + String(pictureNumber) + ".jpg";
fs::FS &fs = SD_MMC;
Serial.printf("Picture file name: %s\n", path.c_str());
After saving the photo, the picture number is stored back into EEPROM for retrieval in the next power
cycle.
File file = fs.open(path.c_str(), FILE_WRITE);
if (!file) {
(continues on next page)
164 Chapter 1. For Arduino User

Table of Contents