pleasedontcode

Camera Commander rev_01

Oct 28th, 2025
439
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 Commander
  13.     - Source Code NOT compiled for: XIAO ESP32S3
  14.     - Source Code created on: 2025-10-28 05:04:58
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* use platformio to program my "seeed xaio esp32s3 */
  21.     /* sense". i need to train an ai model to classify 4 */
  22.     /* different check valve cartridges and communicate */
  23.     /* the results to my click plc via rs232.    sensor */
  24.     /* modality - Images with installed camera a */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27.  
  28. /* START CODE */
  29.  
  30. // Include necessary libraries
  31. #include <Arduino.h>
  32. #include "esp_camera.h"
  33.  
  34. // --- Camera Pin Definitions ---
  35. // (Same as before)
  36. #define PWDN_GPIO_NUM     -1
  37. #define RESET_GPIO_NUM    -1
  38. #define XCLK_GPIO_NUM     10
  39. #define SIOD_GPIO_NUM     40
  40. #define SIOC_GPIO_NUM     39
  41. #define Y9_GPIO_NUM       48
  42. #define Y8_GPIO_NUM       11
  43. #define Y7_GPIO_NUM       12
  44. #define Y6_GPIO_NUM       14
  45. #define Y5_GPIO_NUM       16
  46. #define Y4_GPIO_NUM       18
  47. #define Y3_GPIO_NUM       17
  48. #define Y2_GPIO_NUM       15
  49. #define VSYNC_GPIO_NUM    38
  50. #define HREF_GPIO_NUM     47
  51. #define PCLK_GPIO_NUM     13
  52.  
  53. // Setup function
  54. void setup() {
  55.   Serial.begin(115200);
  56.   Serial.println("ESP32 Serial Data Collector Ready. Send 'c' to capture.");
  57.  
  58.   // Camera configuration
  59.   camera_config_t config;
  60.   config.ledc_channel = LEDC_CHANNEL_0;
  61.   config.ledc_timer = LEDC_TIMER_0;
  62.   config.pin_d0 = Y2_GPIO_NUM;
  63.   config.pin_d1 = Y3_GPIO_NUM;
  64.   config.pin_d2 = Y4_GPIO_NUM;
  65.   config.pin_d3 = Y5_GPIO_NUM;
  66.   config.pin_d4 = Y6_GPIO_NUM;
  67.   config.pin_d5 = Y7_GPIO_NUM;
  68.   config.pin_d6 = Y8_GPIO_NUM;
  69.   config.pin_d7 = Y9_GPIO_NUM;
  70.   config.pin_xclk = XCLK_GPIO_NUM;
  71.   config.pin_pclk = PCLK_GPIO_NUM;
  72.   config.pin_vsync = VSYNC_GPIO_NUM;
  73.   config.pin_href = HREF_GPIO_NUM;
  74.   config.pin_sccb_sda = SIOD_GPIO_NUM;
  75.   config.pin_sccb_scl = SIOC_GPIO_NUM;
  76.   config.pin_pwdn = PWDN_GPIO_NUM;
  77.   config.pin_reset = RESET_GPIO_NUM;
  78.   config.xclk_freq_hz = 20000000;
  79.   config.pixel_format = PIXFORMAT_JPEG;
  80.   config.frame_size = FRAMESIZE_QVGA; // 320x240
  81.   config.jpeg_quality = 10;
  82.   config.fb_count = 1;
  83.  
  84.   // Initialize camera
  85.   esp_err_t err = esp_camera_init(&config);
  86.   if (err != ESP_OK) {
  87.     Serial.printf("Camera init failed with error 0x%x\n", err);
  88.     return;
  89.   }
  90.   Serial.println("Camera initialized successfully.");
  91. }
  92.  
  93. // Loop function
  94. void loop() {
  95.   if (Serial.available() > 0) {
  96.     char command = Serial.read();
  97.     if (command == 'c') {
  98.       camera_fb_t *fb = esp_camera_fb_get();
  99.       if (!fb) {
  100.         Serial.println("FAIL");
  101.         return;
  102.       }
  103.       // Send a header with the image size
  104.       Serial.printf("START,%d\n", fb->len);
  105.       // Write the raw image data
  106.       Serial.write(fb->buf, fb->len);
  107.       // Wait for the serial buffer to be empty before continuing
  108.       Serial.flush();
  109.       // Send a footer to mark end of image data
  110.       Serial.println("END");
  111.       esp_camera_fb_return(fb);
  112.     }
  113.   }
  114. }
  115.  
  116. /* END CODE */
  117.  
Advertisement
Add Comment
Please, Sign In to add comment