Advertisement
microrobotics

ESP32-CAM board with an OV5640

Apr 24th, 2023
3,699
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Here's an example code for the ESP32-CAM board with an OV5640 camera module that streams video feed on a web server. Make sure you have installed the "esp32" board support in the Arduino IDE before proceeding.
  3.  
  4. Replace your_SSID and your_PASSWORD with your WiFi network credentials. Upload the code to your ESP32-CAM board using an FTDI programmer or similar method.
  5.  
  6. After uploading, open the Serial Monitor and press the reset button on the ESP32-CAM board. Note down the IP address displayed in the Serial Monitor. Open a web browser and enter the IP address. You should see the video feed from the OV5640 camera module.
  7.  
  8. Please note that this code assumes you are using the AI-THINKER ESP32-CAM model with an OV5640 camera module. If you're using a different model or configuration, you might need to modify the camera pins according to your specific board.
  9.  
  10. Also, make sure you have selected the "ESP32 Wrover Module" board in the Arduino IDE with the "Huge APP" partition scheme before uploading the code.
  11. */
  12.  
  13. #include "esp_camera.h"
  14. #include <WiFi.h>
  15.  
  16. // Replace with your network credentials
  17. const char* ssid = "your_SSID";
  18. const char* password = "your_PASSWORD";
  19.  
  20. // OV5640 camera module pins configuration for AI-THINKER Model
  21. int sda = 21;
  22. int scl = 22;
  23. int addr = 0x30;
  24.  
  25. void setup() {
  26.   Serial.begin(115200);
  27.   Serial.setDebugOutput(true);
  28.   Serial.println();
  29.  
  30.   camera_config_t config;
  31.   config.ledc_channel = LEDC_CHANNEL_0;
  32.   config.ledc_timer = LEDC_TIMER_0;
  33.   config.pin_d0 = 5;
  34.   config.pin_d1 = 18;
  35.   config.pin_d2 = 19;
  36.   config.pin_d3 = 21;
  37.   config.pin_d4 = 36;
  38.   config.pin_d5 = 39;
  39.   config.pin_d6 = 34;
  40.   config.pin_d7 = 35;
  41.   config.pin_xclk = 0;
  42.   config.pin_pclk = 22;
  43.   config.pin_vsync = 25;
  44.   config.pin_href = 23;
  45.   config.pin_sscb_sda = sda;
  46.   config.pin_sscb_scl = scl;
  47.   config.pin_pwdn = 32;
  48.   config.pin_reset = -1;
  49.   config.xclk_freq_hz = 20000000;
  50.   config.pixel_format = PIXFORMAT_JPEG;
  51.   config.frame_size = FRAMESIZE_UXGA;
  52.   config.jpeg_quality = 10;
  53.   config.fb_count = 1;
  54.  
  55.   // Camera init
  56.   esp_err_t err = esp_camera_init(&config);
  57.   if (err != ESP_OK) {
  58.     Serial.printf("Camera init failed with error 0x%x", err);
  59.     return;
  60.   }
  61.  
  62.   // Connect to Wi-Fi
  63.   WiFi.begin(ssid, password);
  64.   while (WiFi.status() != WL_CONNECTED) {
  65.     delay(500);
  66.     Serial.print(".");
  67.   }
  68.   Serial.println("");
  69.   Serial.println("WiFi connected");
  70.  
  71.   // Start streaming web server
  72.   startCameraServer();
  73.  
  74.   Serial.print("Camera Ready! Use 'http://");
  75.   Serial.print(WiFi.localIP());
  76.   Serial.println("' to connect");
  77. }
  78.  
  79. void loop() {
  80.   // Nothing to do here
  81. }
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement