ESP32-CAM简介

ESP32-CAM摄像头开发板上手体验 - 图1
ESP32-CAM是安信可最新发布小尺寸的摄像头模组。该模块可以作为最小系统独立工作,尺寸仅为2740.54.5mm,深度睡眠电流最低达到6mA。
ESP32-CAM可广泛应用于各种物联网场合,适用于家庭智能设备、工业无线控制、无线监控、QR无线识别,无线定位系统信号以及其它物联网应用,是物联网应用的理想解决方案。
ESP32-CAM采用DIP封装,直接插上底板即可使用,实现产品的快速生产,为客户提供高可靠性的连接方式,方便应用于各种物联网硬件终端场合。
体积超小的802.11b/g/n Wi-Fi + BT/BLE SoC模块

产品参数

采用低功耗双核32位CPU,可作应用处理器
主频高达240MHz,运算能力高达 600 DMIPS
内置 520 KB SRAM,外置8MB PSRAM
支持UART/SPI/I2C/PWM/ADC/DAC等接口
支持OV2640和OV7670摄像头,内置闪光灯
支持图片WiFI上传
支持TF卡
支持多种休眠模式。
内嵌Lwip和FreeRTOS
支持 STA/AP/STA+AP 工作模式
支持 Smart Config/AirKiss 一键配网
支持二次开发

应用场景

家庭智能设备图传
无线监控
智慧农业
QR无线识别

引脚定义

ESP32-CAM摄像头开发板上手体验 - 图2
ESP32-CAM摄像头开发板上手体验 - 图3

规格书

esp32-cam_product_specification_zh.pdf

原理图

esp32_cam_sch.pdf

Arduino开发

开发板连线

有烧录底板

无烧录底板

配置开发板

配置ESP32库的开发板地址

  1. https://dl.espressif.com/dl/package_esp32_index.json

ESP32-CAM摄像头开发板上手体验 - 图4

安装ESP32开发板环境

ESP32-CAM摄像头开发板上手体验 - 图5

打开示例

image.png

选择模组型号

选择安信可的模式
image.png
修改WiFi名称及密码
image.png

选择开发板型号

image.png

编译并上传代码

查看IP地址

通过安信可串口工具,选择相应的串口号和波特率,然后复位一下。通过串口工具即可获取到当前摄像头开发板的ip地址。

参考代码

实例代码只展示CameraWebServer,其更详细代码在文章附件中下载

STA模式参考代码

  1. #include "esp_camera.h"
  2. #include <WiFi.h>
  3. //
  4. // WARNING!!! PSRAM IC required for UXGA resolution and high JPEG quality
  5. // Ensure ESP32 Wrover Module or other board with PSRAM is selected
  6. // Partial images will be transmitted if image exceeds buffer size
  7. //
  8. // Select camera model
  9. //#define CAMERA_MODEL_WROVER_KIT // Has PSRAM
  10. //#define CAMERA_MODEL_ESP_EYE // Has PSRAM
  11. //#define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM
  12. //#define CAMERA_MODEL_M5STACK_V2_PSRAM // M5Camera version B Has PSRAM
  13. //#define CAMERA_MODEL_M5STACK_WIDE // Has PSRAM
  14. //#define CAMERA_MODEL_M5STACK_ESP32CAM // No PSRAM
  15. //#define CAMERA_MODEL_M5STACK_UNITCAM // No PSRAM
  16. #define CAMERA_MODEL_AI_THINKER // Has PSRAM
  17. //#define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM
  18. #include "camera_pins.h"
  19. const char* ssid = "*********";
  20. const char* password = "*********";
  21. void startCameraServer();
  22. void setup() {
  23. Serial.begin(115200);
  24. Serial.setDebugOutput(true);
  25. Serial.println();
  26. camera_config_t config;
  27. config.ledc_channel = LEDC_CHANNEL_0;
  28. config.ledc_timer = LEDC_TIMER_0;
  29. config.pin_d0 = Y2_GPIO_NUM;
  30. config.pin_d1 = Y3_GPIO_NUM;
  31. config.pin_d2 = Y4_GPIO_NUM;
  32. config.pin_d3 = Y5_GPIO_NUM;
  33. config.pin_d4 = Y6_GPIO_NUM;
  34. config.pin_d5 = Y7_GPIO_NUM;
  35. config.pin_d6 = Y8_GPIO_NUM;
  36. config.pin_d7 = Y9_GPIO_NUM;
  37. config.pin_xclk = XCLK_GPIO_NUM;
  38. config.pin_pclk = PCLK_GPIO_NUM;
  39. config.pin_vsync = VSYNC_GPIO_NUM;
  40. config.pin_href = HREF_GPIO_NUM;
  41. config.pin_sscb_sda = SIOD_GPIO_NUM;
  42. config.pin_sscb_scl = SIOC_GPIO_NUM;
  43. config.pin_pwdn = PWDN_GPIO_NUM;
  44. config.pin_reset = RESET_GPIO_NUM;
  45. config.xclk_freq_hz = 20000000;
  46. config.pixel_format = PIXFORMAT_JPEG;
  47. // if PSRAM IC present, init with UXGA resolution and higher JPEG quality
  48. // for larger pre-allocated frame buffer.
  49. if(psramFound()){
  50. config.frame_size = FRAMESIZE_UXGA;
  51. config.jpeg_quality = 10;
  52. config.fb_count = 2;
  53. } else {
  54. config.frame_size = FRAMESIZE_SVGA;
  55. config.jpeg_quality = 12;
  56. config.fb_count = 1;
  57. }
  58. #if defined(CAMERA_MODEL_ESP_EYE)
  59. pinMode(13, INPUT_PULLUP);
  60. pinMode(14, INPUT_PULLUP);
  61. #endif
  62. // camera init
  63. esp_err_t err = esp_camera_init(&config);
  64. if (err != ESP_OK) {
  65. Serial.printf("Camera init failed with error 0x%x", err);
  66. return;
  67. }
  68. sensor_t * s = esp_camera_sensor_get();
  69. // initial sensors are flipped vertically and colors are a bit saturated
  70. if (s->id.PID == OV3660_PID) {
  71. s->set_vflip(s, 1); // flip it back
  72. s->set_brightness(s, 1); // up the brightness just a bit
  73. s->set_saturation(s, -2); // lower the saturation
  74. }
  75. // drop down frame size for higher initial frame rate
  76. s->set_framesize(s, FRAMESIZE_QVGA);
  77. #if defined(CAMERA_MODEL_M5STACK_WIDE) || defined(CAMERA_MODEL_M5STACK_ESP32CAM)
  78. s->set_vflip(s, 1);
  79. s->set_hmirror(s, 1);
  80. #endif
  81. WiFi.begin(ssid, password);
  82. while (WiFi.status() != WL_CONNECTED) {
  83. delay(500);
  84. Serial.print(".");
  85. }
  86. Serial.println("");
  87. Serial.println("WiFi connected");
  88. startCameraServer();
  89. Serial.print("Camera Ready! Use 'http://");
  90. Serial.print(WiFi.localIP());
  91. Serial.println("' to connect");
  92. }
  93. void loop() {
  94. // put your main code here, to run repeatedly:
  95. delay(10000);
  96. }

STA模式下,连接代码中指定的WiFi,通过串口工具,会显示当前ESP32-CAM分配到的IP地址,通过地址可以进入到ESP32-CAM后台控制界面。

AP模式参考代码

  1. #include "esp_camera.h"
  2. #include <WiFi.h>
  3. #include <WiFiAP.h>
  4. #define CAMERA_MODEL_AI_THINKER // Has PSRAM
  5. #include "camera_pins.h"
  6. IPAddress local_IP(192, 168, 4, 1);
  7. IPAddress gateway(192, 168, 4, 1);
  8. IPAddress subnet(255, 255, 255, 0);
  9. WiFiServer server(80);
  10. void startCameraServer();
  11. void setup() {
  12. Serial.begin(115200);
  13. Serial.setDebugOutput(true);
  14. Serial.println();
  15. camera_config_t config;
  16. config.ledc_channel = LEDC_CHANNEL_0;
  17. config.ledc_timer = LEDC_TIMER_0;
  18. config.pin_d0 = Y2_GPIO_NUM;
  19. config.pin_d1 = Y3_GPIO_NUM;
  20. config.pin_d2 = Y4_GPIO_NUM;
  21. config.pin_d3 = Y5_GPIO_NUM;
  22. config.pin_d4 = Y6_GPIO_NUM;
  23. config.pin_d5 = Y7_GPIO_NUM;
  24. config.pin_d6 = Y8_GPIO_NUM;
  25. config.pin_d7 = Y9_GPIO_NUM;
  26. config.pin_xclk = XCLK_GPIO_NUM;
  27. config.pin_pclk = PCLK_GPIO_NUM;
  28. config.pin_vsync = VSYNC_GPIO_NUM;
  29. config.pin_href = HREF_GPIO_NUM;
  30. config.pin_sscb_sda = SIOD_GPIO_NUM;
  31. config.pin_sscb_scl = SIOC_GPIO_NUM;
  32. config.pin_pwdn = PWDN_GPIO_NUM;
  33. config.pin_reset = RESET_GPIO_NUM;
  34. config.xclk_freq_hz = 20000000;
  35. config.pixel_format = PIXFORMAT_JPEG;
  36. // if PSRAM IC present, init with UXGA resolution and higher JPEG quality
  37. // for larger pre-allocated frame buffer.
  38. if(psramFound()){
  39. config.frame_size = FRAMESIZE_UXGA;
  40. config.jpeg_quality = 10;
  41. config.fb_count = 2;
  42. } else {
  43. config.frame_size = FRAMESIZE_SVGA;
  44. config.jpeg_quality = 12;
  45. config.fb_count = 1;
  46. }
  47. #if defined(CAMERA_MODEL_ESP_EYE)
  48. pinMode(13, INPUT_PULLUP);
  49. pinMode(14, INPUT_PULLUP);
  50. #endif
  51. // camera init
  52. esp_err_t err = esp_camera_init(&config);
  53. if (err != ESP_OK) {
  54. Serial.printf("Camera init failed with error 0x%x", err);
  55. return;
  56. }
  57. sensor_t * s = esp_camera_sensor_get();
  58. // initial sensors are flipped vertically and colors are a bit saturated
  59. if (s->id.PID == OV3660_PID) {
  60. s->set_vflip(s, 1); // flip it back
  61. s->set_brightness(s, 1); // up the brightness just a bit
  62. s->set_saturation(s, -2); // lower the saturation
  63. }
  64. // drop down frame size for higher initial frame rate
  65. s->set_framesize(s, FRAMESIZE_QVGA);
  66. #if defined(CAMERA_MODEL_M5STACK_WIDE) || defined(CAMERA_MODEL_M5STACK_ESP32CAM)
  67. s->set_vflip(s, 1);
  68. s->set_hmirror(s, 1);
  69. #endif
  70. WiFi.softAPConfig(local_IP,gateway,subnet);
  71. WiFi.softAP("ESP32-Cam");
  72. // WiFi.softAPConfig(local_IP, gateway, subnet); //设置AP地址
  73. // IPAddress myIP = WiFi.softAPIP();
  74. // Serial.print("AP IP address: ");
  75. // Serial.println(myIP);
  76. // server.begin();
  77. Serial.println("Server started");
  78. startCameraServer();
  79. Serial.print("Camera Ready! Use 'http://192.168.4.1 to connect");
  80. // Serial.print("Camera Ready! Use 'http://");
  81. // Serial.print(WiFi.localIP());
  82. // Serial.println("' to connect");
  83. }
  84. void loop() {
  85. // put your main code here, to run repeatedly:
  86. delay(10000);
  87. }

AP模式下,ESP32-CAM会发出热点(ESP32-Cam)的热点信号,通过浏览器输入192.168.4.1即可进入到ESP32-CAM的后台界面
image.png
你可以在附件中下载AP模式固件,通过ESPHome-Flash烧录软件下载固件到ESP32-Cam中。

参考资料:

安信可ESP32-CAM摄像头开发demo—局域网拍照、实时视频、人脸识别
arduino配置esp32-cam开发环境
arduino-esp32-cam环境配置和例程使用
ESP32-CAM Take Photo and Save to MicroSD Card
Arduino ESP32-CAM 学习之旅③ 简单剖析官方案例源码,揭开ESP32-CAM神秘面纱

附件:

安信可串口助手.zip
ESPFlashDownloadTool烧录软件.7z
ESP32-CAM测试固件.zip
CameraWebServer.zip
ESPHome-Flasher.zip
AP_ESP32-CAM固件.zip
[

](https://docs.ai-thinker.com/esp32-cam)