· 6 months ago · Apr 06, 2025, 01:55 AM
1/********* Pleasedontcode.com **********
2
3 Pleasedontcode thanks you for automatic code generation! Enjoy your code!
4
5 - Terms and Conditions:
6 You have a non-exclusive, revocable, worldwide, royalty-free license
7 for personal and commercial use. Attribution is optional; modifications
8 are allowed, but you're responsible for code maintenance. We're not
9 liable for any loss or damage. For full terms,
10 please visit pleasedontcode.com/termsandconditions.
11
12 - Project: **Camera Server**
13 - Source Code NOT compiled for: ESP32 DevKit V1
14 - Source Code created on: 2025-04-06 01:50:17
15
16********* Pleasedontcode.com **********/
17
18/****** SYSTEM REQUIREMENTS *****/
19/****** SYSTEM REQUIREMENT 1 *****/
20 /* The project shall configure all connected */
21 /* components during setup and perform periodic */
22 /* checks in the loop to update their status, */
23 /* ensuring seamless interaction and functionality. */
24/****** END SYSTEM REQUIREMENTS *****/
25
26/* START CODE */
27
28/****** DEFINITION OF LIBRARIES *****/
29#include <WiFi.h>
30#include "camera_pins.h" // Include camera pins header
31
32/****** FUNCTION PROTOTYPES *****/
33void setup(void);
34void loop(void);
35void startCameraServer();
36void setupLedFlash(int pin);
37void updateOutputs(); // Function to update output states
38
39/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
40const uint8_t myLED_LED_PIN_D4 = 4;
41
42/***** DEFINITION OF OUTPUT RAW VARIABLES *****/
43/***** used to store raw data *****/
44bool myLED_LED_PIN_D4_rawData = 0;
45
46/***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
47/***** used to store data after characteristic curve transformation *****/
48float myLED_LED_PIN_D4_phyData = 0.0;
49
50// ===========================
51// Enter your WiFi credentials
52// ===========================
53const char *ssid = "Slibino urvas";
54const char *password = "123st123";
55
56void setup(void)
57{
58 // put your setup code here, to run once:
59 Serial.begin(115200);
60 Serial.setDebugOutput(true);
61 Serial.println();
62
63 pinMode(myLED_LED_PIN_D4, OUTPUT); // Initialize LED pin
64
65 camera_config_t config;
66 config.ledc_channel = LEDC_CHANNEL_0;
67 config.ledc_timer = LEDC_TIMER_0;
68 config.pin_d0 = Y2_GPIO_NUM;
69 config.pin_d1 = Y3_GPIO_NUM;
70 config.pin_d2 = Y4_GPIO_NUM;
71 config.pin_d3 = Y5_GPIO_NUM;
72 config.pin_d4 = Y6_GPIO_NUM;
73 config.pin_d5 = Y7_GPIO_NUM;
74 config.pin_d6 = Y8_GPIO_NUM;
75 config.pin_d7 = Y9_GPIO_NUM;
76 config.pin_xclk = XCLK_GPIO_NUM;
77 config.pin_pclk = PCLK_GPIO_NUM;
78 config.pin_vsync = VSYNC_GPIO_NUM;
79 config.pin_href = HREF_GPIO_NUM;
80 config.pin_sccb_sda = SIOD_GPIO_NUM;
81 config.pin_sccb_scl = SIOC_GPIO_NUM;
82 config.pin_pwdn = PWDN_GPIO_NUM;
83 config.pin_reset = RESET_GPIO_NUM;
84 config.xclk_freq_hz = 20000000;
85 config.frame_size = FRAMESIZE_UXGA;
86 config.pixel_format = PIXFORMAT_JPEG; // for streaming
87 config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
88 config.fb_location = CAMERA_FB_IN_PSRAM;
89 config.jpeg_quality = 12;
90 config.fb_count = 1;
91
92 // if PSRAM IC present, init with UXGA resolution and higher JPEG quality
93 if (config.pixel_format == PIXFORMAT_JPEG) {
94 if (psramFound()) {
95 config.jpeg_quality = 10;
96 config.fb_count = 2;
97 config.grab_mode = CAMERA_GRAB_LATEST;
98 } else {
99 // Limit the frame size when PSRAM is not available
100 config.frame_size = FRAMESIZE_SVGA;
101 config.fb_location = CAMERA_FB_IN_DRAM;
102 }
103 } else {
104 // Best option for face detection/recognition
105 config.frame_size = FRAMESIZE_240X240;
106#if CONFIG_IDF_TARGET_ESP32S3
107 config.fb_count = 2;
108#endif
109 }
110
111#if defined(CAMERA_MODEL_ESP_EYE)
112 pinMode(13, INPUT_PULLUP);
113 pinMode(14, INPUT_PULLUP);
114#endif
115
116 // camera init
117 esp_err_t err = esp_camera_init(&config);
118 if (err != ESP_OK) {
119 Serial.printf("Camera init failed with error 0x%x", err);
120 return;
121 }
122
123 sensor_t *s = esp_camera_sensor_get();
124 // initial sensors are flipped vertically and colors are a bit saturated
125 if (s->id.PID == OV3660_PID) {
126 s->set_vflip(s, 1); // flip it back
127 s->set_brightness(s, 1); // up the brightness just a bit
128 s->set_saturation(s, -2); // lower the saturation
129 }
130 // drop down frame size for higher initial frame rate
131 if (config.pixel_format == PIXFORMAT_JPEG) {
132 s->set_framesize(s, FRAMESIZE_QVGA);
133 }
134
135#if defined(CAMERA_MODEL_M5STACK_WIDE) || defined(CAMERA_MODEL_M5STACK_ESP32CAM)
136 s->set_vflip(s, 1);
137 s->set_hmirror(s, 1);
138#endif
139
140#if defined(CAMERA_MODEL_ESP32S3_EYE)
141 s->set_vflip(s, 1);
142#endif
143
144 // Setup LED Flash if LED pin is defined in camera_pins.h
145#if defined(LED_GPIO_NUM)
146 setupLedFlash(LED_GPIO_NUM);
147#endif
148
149 WiFi.begin(ssid, password);
150 WiFi.setSleep(false);
151
152 Serial.print("WiFi connecting");
153 while (WiFi.status() != WL_CONNECTED) {
154 delay(500);
155 Serial.print(".");
156 }
157 Serial.println("");
158 Serial.println("WiFi connected");
159
160 startCameraServer();
161
162 Serial.print("Camera Ready! Use 'http://");
163 Serial.print(WiFi.localIP());
164 Serial.println("' to connect");
165}
166
167void loop(void)
168{
169 // put your main code here, to run repeatedly:
170 updateOutputs(); // Refresh output data
171 delay(10000); // Wait before the next update
172}
173
174void updateOutputs()
175{
176 digitalWrite(myLED_LED_PIN_D4, myLED_LED_PIN_D4_rawData);
177}
178
179/* END CODE */