Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: Camera Commander
- - Source Code NOT compiled for: XIAO ESP32S3
- - Source Code created on: 2025-10-28 05:04:58
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* use platformio to program my "seeed xaio esp32s3 */
- /* sense". i need to train an ai model to classify 4 */
- /* different check valve cartridges and communicate */
- /* the results to my click plc via rs232. sensor */
- /* modality - Images with installed camera a */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- // Include necessary libraries
- #include <Arduino.h>
- #include "esp_camera.h"
- // --- Camera Pin Definitions ---
- // (Same as before)
- #define PWDN_GPIO_NUM -1
- #define RESET_GPIO_NUM -1
- #define XCLK_GPIO_NUM 10
- #define SIOD_GPIO_NUM 40
- #define SIOC_GPIO_NUM 39
- #define Y9_GPIO_NUM 48
- #define Y8_GPIO_NUM 11
- #define Y7_GPIO_NUM 12
- #define Y6_GPIO_NUM 14
- #define Y5_GPIO_NUM 16
- #define Y4_GPIO_NUM 18
- #define Y3_GPIO_NUM 17
- #define Y2_GPIO_NUM 15
- #define VSYNC_GPIO_NUM 38
- #define HREF_GPIO_NUM 47
- #define PCLK_GPIO_NUM 13
- // Setup function
- void setup() {
- Serial.begin(115200);
- Serial.println("ESP32 Serial Data Collector Ready. Send 'c' to capture.");
- // Camera configuration
- camera_config_t config;
- config.ledc_channel = LEDC_CHANNEL_0;
- config.ledc_timer = LEDC_TIMER_0;
- config.pin_d0 = Y2_GPIO_NUM;
- config.pin_d1 = Y3_GPIO_NUM;
- config.pin_d2 = Y4_GPIO_NUM;
- config.pin_d3 = Y5_GPIO_NUM;
- config.pin_d4 = Y6_GPIO_NUM;
- config.pin_d5 = Y7_GPIO_NUM;
- config.pin_d6 = Y8_GPIO_NUM;
- config.pin_d7 = Y9_GPIO_NUM;
- config.pin_xclk = XCLK_GPIO_NUM;
- config.pin_pclk = PCLK_GPIO_NUM;
- config.pin_vsync = VSYNC_GPIO_NUM;
- config.pin_href = HREF_GPIO_NUM;
- config.pin_sccb_sda = SIOD_GPIO_NUM;
- config.pin_sccb_scl = SIOC_GPIO_NUM;
- config.pin_pwdn = PWDN_GPIO_NUM;
- config.pin_reset = RESET_GPIO_NUM;
- config.xclk_freq_hz = 20000000;
- config.pixel_format = PIXFORMAT_JPEG;
- config.frame_size = FRAMESIZE_QVGA; // 320x240
- config.jpeg_quality = 10;
- config.fb_count = 1;
- // Initialize camera
- esp_err_t err = esp_camera_init(&config);
- if (err != ESP_OK) {
- Serial.printf("Camera init failed with error 0x%x\n", err);
- return;
- }
- Serial.println("Camera initialized successfully.");
- }
- // Loop function
- void loop() {
- if (Serial.available() > 0) {
- char command = Serial.read();
- if (command == 'c') {
- camera_fb_t *fb = esp_camera_fb_get();
- if (!fb) {
- Serial.println("FAIL");
- return;
- }
- // Send a header with the image size
- Serial.printf("START,%d\n", fb->len);
- // Write the raw image data
- Serial.write(fb->buf, fb->len);
- // Wait for the serial buffer to be empty before continuing
- Serial.flush();
- // Send a footer to mark end of image data
- Serial.println("END");
- esp_camera_fb_return(fb);
- }
- }
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment