ESP32 et WEBCAM
Attention : Cette carte nécessite un adaptateur USB FTDI
Pour le temps du téléchargement, il faut relier IOO et GND (source)
Complément :
https://github.com/rzeldent/esp32cam-rtsp
Mise en route ESP32-cam
Dans l'IDE arduino, ajouter si nécessaire https://dl.espressif.com/dl/package_esp32_index.json (séparer par des , si d'autres packages)
Choisir la carte ESP32 wrover module
Régler la partition schéma sur HUGE APP
Ouvrir Exemples /ESP32 / Camera / camera webserver
Dans le code, ajuster les propriétés de votre wifi, et chercher la bonne camera entre les lignes 9 et 14)
Un exemple de code à travailler, ce code permet de prendre deux photos sur une carte sd, puis et placer l'ESP32 en mode veille .
1
/*********2
Rui Santos3
Complete project details at https://RandomNerdTutorials.com/esp32-cam-take-photo-save-microsd-card4
5
IMPORTANT!!! 6
- Select Board "AI Thinker ESP32-CAM"7
- GPIO 0 must be connected to GND to upload a sketch8
- After connecting GPIO 0 to GND, press the ESP32-CAM on-board RESET button to put your board in flashing mode9
10
Permission is hereby granted, free of charge, to any person obtaining a copy11
of this software and associated documentation files.12
The above copyright notice and this permission notice shall be included in all13
copies or substantial portions of the Software.14
*********/15
16
17
18
// SD Card ESP32
19
// SD Card ESP32
20
// Disable brownour problems
21
// Disable brownour problems
22
23
// read and write from flash memory
24
25
// define the number of bytes you want to access26
27
28
// Pin definition for CAMERA_MODEL_AI_THINKER29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
int pictureNumber = 0;
48
49
void setup() {
50
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector
51
52
Serial.begin(115200);
53
//Serial.setDebugOutput(true);54
//Serial.println();55
56
camera_config_t config;
57
config.ledc_channel = LEDC_CHANNEL_0;
58
config.ledc_timer = LEDC_TIMER_0;
59
config.pin_d0 = Y2_GPIO_NUM;
60
config.pin_d1 = Y3_GPIO_NUM;
61
config.pin_d2 = Y4_GPIO_NUM;
62
config.pin_d3 = Y5_GPIO_NUM;
63
config.pin_d4 = Y6_GPIO_NUM;
64
config.pin_d5 = Y7_GPIO_NUM;
65
config.pin_d6 = Y8_GPIO_NUM;
66
config.pin_d7 = Y9_GPIO_NUM;
67
config.pin_xclk = XCLK_GPIO_NUM;
68
config.pin_pclk = PCLK_GPIO_NUM;
69
config.pin_vsync = VSYNC_GPIO_NUM;
70
config.pin_href = HREF_GPIO_NUM;
71
config.pin_sscb_sda = SIOD_GPIO_NUM;
72
config.pin_sscb_scl = SIOC_GPIO_NUM;
73
config.pin_pwdn = PWDN_GPIO_NUM;
74
config.pin_reset = RESET_GPIO_NUM;
75
config.xclk_freq_hz = 20000000;
76
config.pixel_format = PIXFORMAT_JPEG;
77
78
if(psramFound()){
79
config.frame_size = FRAMESIZE_UXGA; // FRAMESIZE_ + QVGA|CIF|VGA|SVGA|XGA|SXGA|UXGA
80
config.jpeg_quality = 10;
81
config.fb_count = 2;
82
} else {83
config.frame_size = FRAMESIZE_SVGA;
84
config.jpeg_quality = 12;
85
config.fb_count = 1;
86
}
87
88
// Init Camera89
esp_err_t err = esp_camera_init(&config);
90
if (err != ESP_OK) {
91
Serial.printf("Camera init failed with error 0x%x", err);
92
return;93
}
94
95
//Serial.println("Starting SD Card");96
if(!SD_MMC.begin()){
97
Serial.println("SD Card Mount Failed");
98
return;99
}
100
101
uint8_t cardType = SD_MMC.cardType();
102
if(cardType == CARD_NONE){
103
Serial.println("No SD Card attached");
104
return;105
}
106
107
camera_fb_t * fb = NULL;
108
109
// Take Picture with Camera110
fb = esp_camera_fb_get();
111
if(!fb) {
112
Serial.println("Camera capture failed");
113
return;114
}
115
// initialize EEPROM with predefined size116
EEPROM.begin(EEPROM_SIZE);
117
pictureNumber = EEPROM.read(0) + 1;
118
119
// Path where new picture will be saved in SD Card120
String path = "/picture" + String(pictureNumber) +".jpg";
121
122
fs::FS &fs = SD_MMC;
123
Serial.printf("Picture file name: %s\n", path.c_str());
124
125
File file = fs.open(path.c_str(), FILE_WRITE);
126
if(!file){
127
Serial.println("Failed to open file in writing mode");
128
}
129
else {130
file.write(fb->buf, fb->len); // payload (image), payload length
131
Serial.printf("Saved file to path: %s\n", path.c_str());
132
EEPROM.write(0, pictureNumber);
133
EEPROM.commit();
134
}
135
file.close();
136
esp_camera_fb_return(fb);
137
138
// Turns off the ESP32-CAM white on-board LED (flash) connected to GPIO 4139
pinMode(4, OUTPUT);
140
digitalWrite(4, LOW);
141
rtc_gpio_hold_en(GPIO_NUM_4);
142
143
delay(2000);
144
Serial.println("Going to sleep now");
145
delay(2000);
146
esp_deep_sleep_start();147
Serial.println("This will never be printed");
148
}
149
150
void loop() {
151
152
}

