Guest User

Untitled

a guest
Feb 5th, 2025
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.08 KB | None | 0 0
  1. #include "esp_camera.h"
  2. #include <WiFi.h>
  3.  
  4. //
  5. // WARNING!!! PSRAM IC required for UXGA resolution and high JPEG quality
  6. // Ensure ESP32 Wrover Module or other board with PSRAM is selected
  7. // Partial images will be transmitted if image exceeds buffer size
  8. //
  9. // You must select partition scheme from the board menu that has at least 3MB APP space.
  10. // Face Recognition is DISABLED for ESP32 and ESP32-S2, because it takes up from 15
  11. // seconds to process single frame. Face Detection is ENABLED if PSRAM is enabled as well
  12.  
  13. // ===================
  14. // Select camera model
  15. // ===================
  16. //#define CAMERA_MODEL_WROVER_KIT // Has PSRAM
  17. //#define CAMERA_MODEL_ESP_EYE // Has PSRAM
  18. //#define CAMERA_MODEL_ESP32S3_EYE // Has PSRAM
  19. //#define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM
  20. //#define CAMERA_MODEL_M5STACK_V2_PSRAM // M5Camera version B Has PSRAM
  21. //#define CAMERA_MODEL_M5STACK_WIDE // Has PSRAM
  22. //#define CAMERA_MODEL_M5STACK_ESP32CAM // No PSRAM
  23. //#define CAMERA_MODEL_M5STACK_UNITCAM // No PSRAM
  24. //#define CAMERA_MODEL_M5STACK_CAMS3_UNIT // Has PSRAM
  25. #define CAMERA_MODEL_AI_THINKER // Has PSRAM
  26. //#define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM
  27. //#define CAMERA_MODEL_XIAO_ESP32S3 // Has PSRAM
  28. // ** Espressif Internal Boards **
  29. //#define CAMERA_MODEL_ESP32_CAM_BOARD
  30. //#define CAMERA_MODEL_ESP32S2_CAM_BOARD
  31. //#define CAMERA_MODEL_ESP32S3_CAM_LCD
  32. //#define CAMERA_MODEL_DFRobot_FireBeetle2_ESP32S3 // Has PSRAM
  33. //#define CAMERA_MODEL_DFRobot_Romeo_ESP32S3 // Has PSRAM
  34. #include "camera_pins.h"
  35.  
  36. // ===========================
  37. // Enter your WiFi credentials
  38. // ===========================
  39. const char *ssid = "xxxxxxxx";
  40. const char *password = "xxxxxxxx";
  41.  
  42. void startCameraServer();
  43. void setupLedFlash(int pin);
  44.  
  45. void setup() {
  46. Serial.begin(115200);
  47. Serial.setDebugOutput(true);
  48. Serial.println();
  49.  
  50. camera_config_t config;
  51. config.ledc_channel = LEDC_CHANNEL_0;
  52. config.ledc_timer = LEDC_TIMER_0;
  53. config.pin_d0 = Y2_GPIO_NUM;
  54. config.pin_d1 = Y3_GPIO_NUM;
  55. config.pin_d2 = Y4_GPIO_NUM;
  56. config.pin_d3 = Y5_GPIO_NUM;
  57. config.pin_d4 = Y6_GPIO_NUM;
  58. config.pin_d5 = Y7_GPIO_NUM;
  59. config.pin_d6 = Y8_GPIO_NUM;
  60. config.pin_d7 = Y9_GPIO_NUM;
  61. config.pin_xclk = XCLK_GPIO_NUM;
  62. config.pin_pclk = PCLK_GPIO_NUM;
  63. config.pin_vsync = VSYNC_GPIO_NUM;
  64. config.pin_href = HREF_GPIO_NUM;
  65. config.pin_sccb_sda = SIOD_GPIO_NUM;
  66. config.pin_sccb_scl = SIOC_GPIO_NUM;
  67. config.pin_pwdn = PWDN_GPIO_NUM;
  68. config.pin_reset = RESET_GPIO_NUM;
  69. config.xclk_freq_hz = 20000000;
  70. config.frame_size = FRAMESIZE_UXGA;
  71. config.pixel_format = PIXFORMAT_JPEG; // for streaming
  72. //config.pixel_format = PIXFORMAT_RGB565; // for face detection/recognition
  73. config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
  74. config.fb_location = CAMERA_FB_IN_PSRAM;
  75. config.jpeg_quality = 12;
  76. config.fb_count = 1;
  77.  
  78. // if PSRAM IC present, init with UXGA resolution and higher JPEG quality
  79. // for larger pre-allocated frame buffer.
  80. if (config.pixel_format == PIXFORMAT_JPEG) {
  81. if (psramFound()) {
  82. config.jpeg_quality = 10;
  83. config.fb_count = 2;
  84. config.grab_mode = CAMERA_GRAB_LATEST;
  85. } else {
  86. // Limit the frame size when PSRAM is not available
  87. config.frame_size = FRAMESIZE_SVGA;
  88. config.fb_location = CAMERA_FB_IN_DRAM;
  89. }
  90. } else {
  91. // Best option for face detection/recognition
  92. config.frame_size = FRAMESIZE_240X240;
  93. #if CONFIG_IDF_TARGET_ESP32S3
  94. config.fb_count = 2;
  95. #endif
  96. }
  97.  
  98. #if defined(CAMERA_MODEL_ESP_EYE)
  99. pinMode(13, INPUT_PULLUP);
  100. pinMode(14, INPUT_PULLUP);
  101. #endif
  102.  
  103. // camera init
  104. esp_err_t err = esp_camera_init(&config);
  105. if (err != ESP_OK) {
  106. Serial.printf("Camera init failed with error 0x%x", err);
  107. return;
  108. }
  109.  
  110. sensor_t *s = esp_camera_sensor_get();
  111. // initial sensors are flipped vertically and colors are a bit saturated
  112. if (s->id.PID == OV3660_PID) {
  113. s->set_vflip(s, 1); // flip it back
  114. s->set_brightness(s, 1); // up the brightness just a bit
  115. s->set_saturation(s, -2); // lower the saturation
  116. }
  117. // drop down frame size for higher initial frame rate
  118. if (config.pixel_format == PIXFORMAT_JPEG) {
  119. s->set_framesize(s, FRAMESIZE_QVGA);
  120. }
  121.  
  122. #if defined(CAMERA_MODEL_M5STACK_WIDE) || defined(CAMERA_MODEL_M5STACK_ESP32CAM)
  123. s->set_vflip(s, 1);
  124. s->set_hmirror(s, 1);
  125. #endif
  126.  
  127. #if defined(CAMERA_MODEL_ESP32S3_EYE)
  128. s->set_vflip(s, 1);
  129. #endif
  130.  
  131. // Setup LED FLash if LED pin is defined in camera_pins.h
  132. #if defined(LED_GPIO_NUM)
  133. setupLedFlash(LED_GPIO_NUM);
  134. #endif
  135.  
  136. WiFi.begin(ssid, password);
  137. WiFi.setSleep(false);
  138.  
  139. Serial.print("WiFi connecting");
  140. while (WiFi.status() != WL_CONNECTED) {
  141. delay(500);
  142. Serial.print(".");
  143. }
  144. Serial.println("");
  145. Serial.println("WiFi connected");
  146.  
  147. startCameraServer();
  148.  
  149. Serial.print("Camera Ready! Use 'http://");
  150. Serial.print(WiFi.localIP());
  151. Serial.println("' to connect");
  152. }
  153.  
  154. void loop() {
  155. // Do nothing. Everything is done in another task by the web server
  156. delay(10000);
  157. }
  158.  
Advertisement
Add Comment
Please, Sign In to add comment