Hallo,
ich experimentiere hier gerade mit der ESP32 CAM. Ich verwende den Code von Edi's Techlab, das Programm nimmt dann in 10 Sekunden Intervallen Bilder auf und speichert sie auf der microSD-Karte. Das funktioniert auch grundsätzlich, nur das Problem ist, dass alle Bilder auf der SD grün verfärbt sind.
MfG Der Systemelektroniker
/*
Project: ESP32-CAM Time lapse - save pictures on SD-Card
Author: Thomas Edlinger for www.edistechlab.com
Date: Created 07.11.2020
Version: V1.0
IDE: Arduino IDE 1.8.13
Required Board (Tools -> Board -> Boards Manager...)
- Board: esp32 by Espressif Systems V1.0.4
*/
#include "esp_camera.h"
#include "SD_MMC.h"
#include "EEPROM.h"
#include "driver/rtc_io.h"
#include "soc/soc.h" // Schaltet das brownour Problem aus
#include "soc/rtc_cntl_reg.h" // Schaltet das brownour Problem aus
#define ID_ADDRESS 0x00
#define COUNT_ADDRESS 0x01
#define ID_BYTE 0xAA
#define EEPROM_SIZE 0x0F
#define sleepTime 10e6 // Deep Sleep Zeit 10 Sekunden
//#define sleepTime 10e6 // Deep Sleep Zeit 10 Sekunden
uint16_t fotoNummer = 0;
void setup() {
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); // Schaltet den brownour Sensor aus
Serial.begin(115200);
pinMode(4, OUTPUT);
rtc_gpio_hold_dis(GPIO_NUM_4);
// Pin Definition für CAMERA_MODEL_AI_THINKER aus dem Webserver Beispiel unter camera_pins.h
camera_config_t config;
config.ledc_channel = LEDC_CHANNEL_0;
config.ledc_timer = LEDC_TIMER_0;
config.pin_d0 = 5;
config.pin_d1 = 18;
config.pin_d2 = 19;
config.pin_d3 = 21;
config.pin_d4 = 36;
config.pin_d5 = 39;
config.pin_d6 = 34;
config.pin_d7 = 35;
config.pin_xclk = 0;
config.pin_pclk = 22;
config.pin_vsync = 25;
config.pin_href = 23;
config.pin_sscb_sda = 26;
config.pin_sscb_scl = 27;
config.pin_pwdn = 32;
config.pin_reset = -1;
config.xclk_freq_hz = 20000000;
config.pixel_format = PIXFORMAT_JPEG;
if(psramFound()){
config.frame_size = FRAMESIZE_UXGA; // 1600x1200
config.jpeg_quality = 10; // Bild mit hoher Qualität
config.fb_count = 2;
} else {
config.frame_size = FRAMESIZE_SVGA;
config.jpeg_quality = 12;
config.fb_count = 1;
}
// Kamera initialisieren
esp_err_t err = esp_camera_init(&config);
if (err != ESP_OK) {
Serial.printf("Kamera Initialisierung fehlgeschlagen Fehler NR: 0x%x", err);
return;
}
sensor_t * s = esp_camera_sensor_get();
s->set_brightness(s, 0); // -2 to 2
s->set_contrast(s, 0); // -2 to 2
s->set_saturation(s, 0); // -2 to 2
s->set_special_effect(s, 0); // 0 to 6 (0 - No Effect, 1 - Negative, 2 - Grayscale, 3 - Red Tint, 4 - Green Tint, 5 - Blue Tint, 6 - Sepia)
s->set_whitebal(s, 1); // 0 = disable , 1 = enable
s->set_awb_gain(s, 1); // 0 = disable , 1 = enable
s->set_wb_mode(s, 0); // 0 to 4 - if awb_gain enabled (0 - Auto, 1 - Sunny, 2 - Cloudy, 3 - Office, 4 - Home)
s->set_exposure_ctrl(s, 1); // 0 = disable , 1 = enable
s->set_aec2(s, 0); // 0 = disable , 1 = enable
s->set_ae_level(s, 0); // -2 to 2
s->set_aec_value(s, 300); // 0 to 1200
s->set_gain_ctrl(s, 1); // 0 = disable , 1 = enable
s->set_agc_gain(s, 0); // 0 to 30
s->set_gainceiling(s, (gainceiling_t)0); // 0 to 6
s->set_bpc(s, 0); // 0 = disable , 1 = enable
s->set_wpc(s, 1); // 0 = disable , 1 = enable
s->set_raw_gma(s, 1); // 0 = disable , 1 = enable
s->set_lenc(s, 1); // 0 = disable , 1 = enable
s->set_hmirror(s, 0); // 0 = disable , 1 = enable
s->set_vflip(s, 0); // 0 = disable , 1 = enable
s->set_dcw(s, 1); // 0 = disable , 1 = enable
s->set_colorbar(s, 0); // 0 = disable , 1 = enable
// Mounten der SD-Karte
if(!SD_MMC.begin()) {
Serial.println("Kann die SD-Karte nicht mounten");
return;
}
uint8_t cardType = SD_MMC.cardType();
if(cardType == CARD_NONE) {
Serial.println("Keine SD-Karte eingelegt");
return;
}
// EEPROM Initialisieren
if (!EEPROM.begin(EEPROM_SIZE)) {
Serial.println("Fehler beim EEPROM initialisieren");
return;
}
if(EEPROM.read(ID_ADDRESS) != ID_BYTE) {
fotoNummer = 0;
EEPROM.write(ID_ADDRESS, ID_BYTE);
EEPROM.commit();
}
else {
EEPROM.get(COUNT_ADDRESS, fotoNummer);
fotoNummer += 1;
}
// Foto machen
camera_fb_t * fb = NULL;
delay(5000);
fb = esp_camera_fb_get();
if (!fb) {
Serial.println("Fotografieren fehlgeschlagen!");
return;
}
// Foto unter diesem Pfad speichern
String path = "/Foto" + String(fotoNummer) + ".jpg";
fs::FS &fs = SD_MMC;
File file = fs.open(path.c_str(), FILE_WRITE);
if(!file) {
Serial.println("Fehler beim File erstellen");
}
else {
file.write(fb->buf, fb->len);
EEPROM.write(COUNT_ADDRESS, fotoNummer);
EEPROM.commit();
}
file.close();
esp_camera_fb_return(fb);
Serial.printf("Foto gespeichert: %s\n", path.c_str());
pinMode(4, OUTPUT);
digitalWrite(4, LOW); //flash LED aus
rtc_gpio_hold_en(GPIO_NUM_4);
delay(1000);
Serial.println("Gehe in den deep-sleep mode");
esp_sleep_enable_timer_wakeup(sleepTime);
esp_deep_sleep_start();
}
void loop() {
}