Advertisement
pleasedontcode

**Camera Control** rev_02

Apr 5th, 2025
482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 Control**
  13.     - Source Code compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2025-04-06 01:51:32
  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 <esp_camera.h> // Include the ESP32 camera library
  31.  
  32. // Define the camera model before including camera_pins.h
  33. #define CAMERA_MODEL_ESP_EYE // Change this to your specific camera model
  34. #include "camera_pins.h" // Include camera pins header
  35.  
  36. /****** FUNCTION PROTOTYPES *****/
  37. void setup(void);
  38. void loop(void);
  39. void startCameraServer();
  40. void setupLedFlash(int pin);
  41. void updateOutputs(); // Function to update output states
  42.  
  43. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  44. const uint8_t myLED_LED_PIN_D4 = 4;
  45.  
  46. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  47. /***** used to store raw data *****/
  48. bool myLED_LED_PIN_D4_rawData = 0;
  49.  
  50. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  51. /***** used to store data after characteristic curve transformation *****/
  52. float myLED_LED_PIN_D4_phyData = 0.0;
  53.  
  54. // ===========================
  55. // Enter your WiFi credentials
  56. // ===========================
  57. const char *ssid = "Slibino urvas";
  58. const char *password = "123st123";
  59.  
  60. void setup(void)
  61. {
  62.     // put your setup code here, to run once:
  63.     Serial.begin(115200);
  64.     Serial.setDebugOutput(true);
  65.     Serial.println();
  66.  
  67.     pinMode(myLED_LED_PIN_D4, OUTPUT); // Initialize LED pin
  68.  
  69.     camera_config_t config;
  70.     config.ledc_channel = LEDC_CHANNEL_0;
  71.     config.ledc_timer = LEDC_TIMER_0;
  72.     config.pin_d0 = Y2_GPIO_NUM;
  73.     config.pin_d1 = Y3_GPIO_NUM;
  74.     config.pin_d2 = Y4_GPIO_NUM;
  75.     config.pin_d3 = Y5_GPIO_NUM;
  76.     config.pin_d4 = Y6_GPIO_NUM;
  77.     config.pin_d5 = Y7_GPIO_NUM;
  78.     config.pin_d6 = Y8_GPIO_NUM;
  79.     config.pin_d7 = Y9_GPIO_NUM;
  80.     config.pin_xclk = XCLK_GPIO_NUM;
  81.     config.pin_pclk = PCLK_GPIO_NUM;
  82.     config.pin_vsync = VSYNC_GPIO_NUM;
  83.     config.pin_href = HREF_GPIO_NUM;
  84.     config.pin_sccb_sda = SIOD_GPIO_NUM;
  85.     config.pin_sccb_scl = SIOC_GPIO_NUM;
  86.     config.pin_pwdn = PWDN_GPIO_NUM;
  87.     config.pin_reset = RESET_GPIO_NUM;
  88.     config.xclk_freq_hz = 20000000;
  89.     config.frame_size = FRAMESIZE_UXGA;
  90.     config.pixel_format = PIXFORMAT_JPEG;  // for streaming
  91.     config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
  92.     config.fb_location = CAMERA_FB_IN_PSRAM;
  93.     config.jpeg_quality = 12;
  94.     config.fb_count = 1;
  95.  
  96.     // if PSRAM IC present, init with UXGA resolution and higher JPEG quality
  97.     if (config.pixel_format == PIXFORMAT_JPEG) {
  98.         if (psramFound()) {
  99.             config.jpeg_quality = 10;
  100.             config.fb_count = 2;
  101.             config.grab_mode = CAMERA_GRAB_LATEST;
  102.         } else {
  103.             // Limit the frame size when PSRAM is not available
  104.             config.frame_size = FRAMESIZE_SVGA;
  105.             config.fb_location = CAMERA_FB_IN_DRAM;
  106.         }
  107.     } else {
  108.         // Best option for face detection/recognition
  109.         config.frame_size = FRAMESIZE_240X240;
  110. #if CONFIG_IDF_TARGET_ESP32S3
  111.         config.fb_count = 2;
  112. #endif
  113.     }
  114.  
  115. #if defined(CAMERA_MODEL_ESP_EYE)
  116.     pinMode(13, INPUT_PULLUP);
  117.     pinMode(14, INPUT_PULLUP);
  118. #endif
  119.  
  120.     // camera init
  121.     esp_err_t err = esp_camera_init(&config);
  122.     if (err != ESP_OK) {
  123.         Serial.printf("Camera init failed with error 0x%x", err);
  124.         return;
  125.     }
  126.  
  127.     sensor_t *s = esp_camera_sensor_get();
  128.     // initial sensors are flipped vertically and colors are a bit saturated
  129.     if (s->id.PID == OV3660_PID) {
  130.         s->set_vflip(s, 1);        // flip it back
  131.         s->set_brightness(s, 1);   // up the brightness just a bit
  132.         s->set_saturation(s, -2);  // lower the saturation
  133.     }
  134.     // drop down frame size for higher initial frame rate
  135.     if (config.pixel_format == PIXFORMAT_JPEG) {
  136.         s->set_framesize(s, FRAMESIZE_QVGA);
  137.     }
  138.  
  139. #if defined(CAMERA_MODEL_M5STACK_WIDE) || defined(CAMERA_MODEL_M5STACK_ESP32CAM)
  140.     s->set_vflip(s, 1);
  141.     s->set_hmirror(s, 1);
  142. #endif
  143.  
  144. #if defined(CAMERA_MODEL_ESP32S3_EYE)
  145.     s->set_vflip(s, 1);
  146. #endif
  147.  
  148.     // Setup LED Flash if LED pin is defined in camera_pins.h
  149. #if defined(LED_GPIO_NUM)
  150.     setupLedFlash(LED_GPIO_NUM);
  151. #endif
  152.  
  153.     WiFi.begin(ssid, password);
  154.     WiFi.setSleep(false);
  155.  
  156.     Serial.print("WiFi connecting");
  157.     while (WiFi.status() != WL_CONNECTED) {
  158.         delay(500);
  159.         Serial.print(".");
  160.     }
  161.     Serial.println("");
  162.     Serial.println("WiFi connected");
  163.  
  164.     startCameraServer();
  165.  
  166.     Serial.print("Camera Ready! Use 'http://");
  167.     Serial.print(WiFi.localIP());
  168.     Serial.println("' to connect");
  169. }
  170.  
  171. void loop(void)
  172. {
  173.     // put your main code here, to run repeatedly:
  174.     updateOutputs(); // Refresh output data
  175.     delay(10000); // Wait before the next update
  176. }
  177.  
  178. void updateOutputs()
  179. {
  180.     digitalWrite(myLED_LED_PIN_D4, myLED_LED_PIN_D4_rawData);
  181. }
  182.  
  183. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement