Skip to content

Commit 1628f53

Browse files
committed
Add Camera WebServer Example
1 parent 3e66aef commit 1628f53

File tree

3 files changed

+740
-0
lines changed

3 files changed

+740
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
#include "esp_camera.h"
2+
#include <WiFi.h>
3+
4+
//
5+
// WARNING!!! Make sure that you have either selected ESP32 Wrover Module,
6+
// or another board which has PSRAM enabled
7+
//
8+
9+
// Select camera model
10+
#define CAMERA_MODEL_WROVER_KIT
11+
//#define CAMERA_MODEL_M5STACK_PSRAM
12+
//#define CAMERA_MODEL_AI_THINKER
13+
14+
const char* ssid = "*********";
15+
const char* password = "*********";
16+
17+
18+
#if defined(CAMERA_MODEL_WROVER_KIT)
19+
#define PWDN_GPIO_NUM -1
20+
#define RESET_GPIO_NUM -1
21+
#define XCLK_GPIO_NUM 21
22+
#define SIOD_GPIO_NUM 26
23+
#define SIOC_GPIO_NUM 27
24+
25+
#define Y9_GPIO_NUM 35
26+
#define Y8_GPIO_NUM 34
27+
#define Y7_GPIO_NUM 39
28+
#define Y6_GPIO_NUM 36
29+
#define Y5_GPIO_NUM 19
30+
#define Y4_GPIO_NUM 18
31+
#define Y3_GPIO_NUM 5
32+
#define Y2_GPIO_NUM 4
33+
#define VSYNC_GPIO_NUM 25
34+
#define HREF_GPIO_NUM 23
35+
#define PCLK_GPIO_NUM 22
36+
37+
#elif defined(CAMERA_MODEL_M5STACK_PSRAM)
38+
#define PWDN_GPIO_NUM -1
39+
#define RESET_GPIO_NUM 15
40+
#define XCLK_GPIO_NUM 27
41+
#define SIOD_GPIO_NUM 25
42+
#define SIOC_GPIO_NUM 23
43+
44+
#define Y9_GPIO_NUM 19
45+
#define Y8_GPIO_NUM 36
46+
#define Y7_GPIO_NUM 18
47+
#define Y6_GPIO_NUM 39
48+
#define Y5_GPIO_NUM 5
49+
#define Y4_GPIO_NUM 34
50+
#define Y3_GPIO_NUM 35
51+
#define Y2_GPIO_NUM 32
52+
#define VSYNC_GPIO_NUM 22
53+
#define HREF_GPIO_NUM 26
54+
#define PCLK_GPIO_NUM 21
55+
56+
#elif defined(CAMERA_MODEL_AI_THINKER)
57+
#define PWDN_GPIO_NUM 32
58+
#define RESET_GPIO_NUM -1
59+
#define XCLK_GPIO_NUM 0
60+
#define SIOD_GPIO_NUM 26
61+
#define SIOC_GPIO_NUM 27
62+
63+
#define Y9_GPIO_NUM 35
64+
#define Y8_GPIO_NUM 34
65+
#define Y7_GPIO_NUM 39
66+
#define Y6_GPIO_NUM 36
67+
#define Y5_GPIO_NUM 21
68+
#define Y4_GPIO_NUM 19
69+
#define Y3_GPIO_NUM 18
70+
#define Y2_GPIO_NUM 5
71+
#define VSYNC_GPIO_NUM 25
72+
#define HREF_GPIO_NUM 23
73+
#define PCLK_GPIO_NUM 22
74+
75+
#else
76+
#error "Camera model not selected"
77+
#endif
78+
79+
void startCameraServer();
80+
81+
void setup() {
82+
Serial.begin(115200);
83+
Serial.setDebugOutput(true);
84+
Serial.println();
85+
86+
camera_config_t config;
87+
config.ledc_channel = LEDC_CHANNEL_0;
88+
config.ledc_timer = LEDC_TIMER_0;
89+
config.pin_d0 = Y2_GPIO_NUM;
90+
config.pin_d1 = Y3_GPIO_NUM;
91+
config.pin_d2 = Y4_GPIO_NUM;
92+
config.pin_d3 = Y5_GPIO_NUM;
93+
config.pin_d4 = Y6_GPIO_NUM;
94+
config.pin_d5 = Y7_GPIO_NUM;
95+
config.pin_d6 = Y8_GPIO_NUM;
96+
config.pin_d7 = Y9_GPIO_NUM;
97+
config.pin_xclk = XCLK_GPIO_NUM;
98+
config.pin_pclk = PCLK_GPIO_NUM;
99+
config.pin_vsync = VSYNC_GPIO_NUM;
100+
config.pin_href = HREF_GPIO_NUM;
101+
config.pin_sscb_sda = SIOD_GPIO_NUM;
102+
config.pin_sscb_scl = SIOC_GPIO_NUM;
103+
config.pin_pwdn = PWDN_GPIO_NUM;
104+
config.pin_reset = RESET_GPIO_NUM;
105+
config.xclk_freq_hz = 20000000;
106+
config.pixel_format = PIXFORMAT_JPEG;
107+
//init with high specs to pre-allocate larger buffers
108+
if(psramFound()){
109+
config.frame_size = FRAMESIZE_UXGA;
110+
config.jpeg_quality = 10;
111+
config.fb_count = 2;
112+
} else {
113+
config.frame_size = FRAMESIZE_SVGA;
114+
config.jpeg_quality = 12;
115+
config.fb_count = 1;
116+
}
117+
118+
// camera init
119+
esp_err_t err = esp_camera_init(&config);
120+
if (err != ESP_OK) {
121+
Serial.printf("Camera init failed with error 0x%x", err);
122+
return;
123+
}
124+
125+
//drop down frame size for higher initial frame rate
126+
sensor_t * s = esp_camera_sensor_get();
127+
s->set_framesize(s, FRAMESIZE_CIF);
128+
129+
WiFi.begin(ssid, password);
130+
131+
while (WiFi.status() != WL_CONNECTED) {
132+
delay(500);
133+
Serial.print(".");
134+
}
135+
Serial.println("");
136+
Serial.println("WiFi connected");
137+
138+
startCameraServer();
139+
140+
Serial.print("Camera Ready! Use 'http://");
141+
Serial.print(WiFi.localIP());
142+
Serial.println("' to connect");
143+
}
144+
145+
void loop() {
146+
// put your main code here, to run repeatedly:
147+
148+
}

0 commit comments

Comments
 (0)