Pārlūkot izejas kodu

添加摄像头模块

xuxinyi 9 mēneši atpakaļ
vecāks
revīzija
eebd73f057
6 mainītis faili ar 234 papildinājumiem un 3 dzēšanām
  1. 30 0
      .vscode/launch.json
  2. 1 1
      main/CMakeLists.txt
  3. 4 0
      main/app_main.c
  4. 187 0
      main/camera.c
  5. 10 0
      main/camera.h
  6. 2 2
      main/wifi_http.c

+ 30 - 0
.vscode/launch.json

@@ -0,0 +1,30 @@
+{
+    "configurations": [
+        {
+            "name": "(gdb) 启动",
+            "type": "cppdbg",
+            "request": "launch",
+            "program": "输入程序名称,例如 ${workspaceFolder}/a.exe",
+            "args": [],
+            "stopAtEntry": false,
+            "cwd": "${fileDirname}",
+            "environment": [],
+            "externalConsole": false,
+            "MIMode": "gdb",
+            "miDebuggerPath": "/path/to/gdb",
+            "setupCommands": [
+                {
+                    "description": "为 gdb 启用整齐打印",
+                    "text": "-enable-pretty-printing",
+                    "ignoreFailures": true
+                },
+                {
+                    "description": "将反汇编风格设置为 Intel",
+                    "text": "-gdb-set disassembly-flavor intel",
+                    "ignoreFailures": true
+                }
+            ]
+        }
+    ],
+    "version": "2.0.0"
+}

+ 1 - 1
main/CMakeLists.txt

@@ -1,2 +1,2 @@
-idf_component_register(SRCS "app_main.c" "wifi_http.c" "http_request.c"
+idf_component_register(SRCS "camera.c" "app_main.c" "wifi_http.c" "http_request.c" "camera.c"
                     INCLUDE_DIRS ".")

+ 4 - 0
main/app_main.c

@@ -5,6 +5,7 @@
 #include "nvs_flash.h"
 #include "wifi_http.h"  // 引入wifi_http.c中的头文件
 #include "http_request.h"  // 引入http_request.c中的头文件
+#include "camera.h"
 
 static const char *TAG = "app_main";
 
@@ -25,6 +26,9 @@ void app_main(void)
     // 等待Wi-Fi连接
     vTaskDelay(10000 / portTICK_PERIOD_MS);
 
+    //take_photo();
+
+    ESP_LOGI(TAG, "测试");
 
     while (true)
     {

+ 187 - 0
main/camera.c

@@ -0,0 +1,187 @@
+/**
+ * This example takes a picture every 5s and print its size on serial monitor.
+ */
+
+// =============================== SETUP ======================================
+
+// 1. Board setup (Uncomment):
+// #define BOARD_WROVER_KIT
+// #define BOARD_ESP32CAM_AITHINKER
+// #define BOARD_ESP32S3_WROOM
+
+/**
+ * 2. Kconfig setup
+ *
+ * If you have a Kconfig file, copy the content from
+ *  https://github.com/espressif/esp32-camera/blob/master/Kconfig into it.
+ * In case you haven't, copy and paste this Kconfig file inside the src directory.
+ * This Kconfig file has definitions that allows more control over the camera and
+ * how it will be initialized.
+ */
+
+/**
+ * 3. Enable PSRAM on sdkconfig:
+ *
+ * CONFIG_ESP32_SPIRAM_SUPPORT=y
+ *
+ * More info on
+ * https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/kconfig.html#config-esp32-spiram-support
+ */
+
+// ================================ CODE ======================================
+
+#include <esp_log.h>
+#include <esp_system.h>
+#include <nvs_flash.h>
+#include <sys/param.h>
+#include <string.h>
+
+#include "freertos/FreeRTOS.h"
+#include "freertos/task.h"
+
+// support IDF 5.x
+#ifndef portTICK_RATE_MS
+#define portTICK_RATE_MS portTICK_PERIOD_MS
+#endif
+
+#include "esp_camera.h"
+
+#define BOARD_WROVER_KIT 1
+
+// WROVER-KIT PIN Map
+#ifdef BOARD_WROVER_KIT
+
+#define CAM_PIN_PWDN -1  //power down is not used
+#define CAM_PIN_RESET -1 //software reset will be performed
+#define CAM_PIN_XCLK 21
+#define CAM_PIN_SIOD 26
+#define CAM_PIN_SIOC 27
+
+#define CAM_PIN_D7 35
+#define CAM_PIN_D6 34
+#define CAM_PIN_D5 39
+#define CAM_PIN_D4 36
+#define CAM_PIN_D3 19
+#define CAM_PIN_D2 18
+#define CAM_PIN_D1 5
+#define CAM_PIN_D0 4
+#define CAM_PIN_VSYNC 25
+#define CAM_PIN_HREF 23
+#define CAM_PIN_PCLK 22
+
+#endif
+
+// ESP32Cam (AiThinker) PIN Map
+#ifdef BOARD_ESP32CAM_AITHINKER
+
+#define CAM_PIN_PWDN 32
+#define CAM_PIN_RESET -1 //software reset will be performed
+#define CAM_PIN_XCLK 0
+#define CAM_PIN_SIOD 26
+#define CAM_PIN_SIOC 27
+
+#define CAM_PIN_D7 35
+#define CAM_PIN_D6 34
+#define CAM_PIN_D5 39
+#define CAM_PIN_D4 36
+#define CAM_PIN_D3 21
+#define CAM_PIN_D2 19
+#define CAM_PIN_D1 18
+#define CAM_PIN_D0 5
+#define CAM_PIN_VSYNC 25
+#define CAM_PIN_HREF 23
+#define CAM_PIN_PCLK 22
+
+#endif
+// ESP32S3 (WROOM) PIN Map
+#ifdef BOARD_ESP32S3_WROOM
+#define CAM_PIN_PWDN 38
+#define CAM_PIN_RESET -1   //software reset will be performed
+#define CAM_PIN_VSYNC 6
+#define CAM_PIN_HREF 7
+#define CAM_PIN_PCLK 13
+#define CAM_PIN_XCLK 15
+#define CAM_PIN_SIOD 4
+#define CAM_PIN_SIOC 5
+#define CAM_PIN_D0 11
+#define CAM_PIN_D1 9
+#define CAM_PIN_D2 8
+#define CAM_PIN_D3 10
+#define CAM_PIN_D4 12
+#define CAM_PIN_D5 18
+#define CAM_PIN_D6 17
+#define CAM_PIN_D7 16
+#endif
+static const char *TAG = "example:take_picture";
+
+#if ESP_CAMERA_SUPPORTED
+static camera_config_t camera_config = {
+    .pin_pwdn = CAM_PIN_PWDN,
+    .pin_reset = CAM_PIN_RESET,
+    .pin_xclk = CAM_PIN_XCLK,
+    .pin_sccb_sda = CAM_PIN_SIOD,
+    .pin_sccb_scl = CAM_PIN_SIOC,
+
+    .pin_d7 = CAM_PIN_D7,
+    .pin_d6 = CAM_PIN_D6,
+    .pin_d5 = CAM_PIN_D5,
+    .pin_d4 = CAM_PIN_D4,
+    .pin_d3 = CAM_PIN_D3,
+    .pin_d2 = CAM_PIN_D2,
+    .pin_d1 = CAM_PIN_D1,
+    .pin_d0 = CAM_PIN_D0,
+    .pin_vsync = CAM_PIN_VSYNC,
+    .pin_href = CAM_PIN_HREF,
+    .pin_pclk = CAM_PIN_PCLK,
+
+    //XCLK 20MHz or 10MHz for OV2640 double FPS (Experimental)
+    .xclk_freq_hz = 20000000,
+    .ledc_timer = LEDC_TIMER_0,
+    .ledc_channel = LEDC_CHANNEL_0,
+
+    .pixel_format = PIXFORMAT_RGB565, //YUV422,GRAYSCALE,RGB565,JPEG
+    .frame_size = FRAMESIZE_QVGA,    //QQVGA-UXGA, For ESP32, do not use sizes above QVGA when not JPEG. The performance of the ESP32-S series has improved a lot, but JPEG mode always gives better frame rates.
+
+    .jpeg_quality = 12, //0-63, for OV series camera sensors, lower number means higher quality
+    .fb_count = 1,       //When jpeg mode is used, if fb_count more than one, the driver will work in continuous mode.
+    .fb_location = CAMERA_FB_IN_PSRAM,
+    .grab_mode = CAMERA_GRAB_WHEN_EMPTY,
+};
+
+static esp_err_t init_camera(void)
+{
+    //initialize the camera
+    esp_err_t err = esp_camera_init(&camera_config);
+    if (err != ESP_OK)
+    {
+        ESP_LOGE(TAG, "Camera Init Failed");
+        return err;
+    }
+
+    return ESP_OK;
+}
+#endif
+
+void take_photo(void)
+{
+#if ESP_CAMERA_SUPPORTED
+    if(ESP_OK != init_camera()) {
+        return;
+    }
+
+    while (1)
+    {
+        ESP_LOGI(TAG, "Taking picture...");
+        camera_fb_t *pic = esp_camera_fb_get();
+
+        // use pic->buf to access the image
+        ESP_LOGI(TAG, "Picture taken! Its size was: %zu bytes", pic->len);
+        esp_camera_fb_return(pic);
+
+        vTaskDelay(5000 / portTICK_RATE_MS);
+    }
+#else
+    ESP_LOGE(TAG, "Camera support is not available for this chip");
+    return;
+#endif
+}

+ 10 - 0
main/camera.h

@@ -0,0 +1,10 @@
+// wifi_http.h
+#ifndef CAMERA_H
+#define CAMERA_H
+
+#include "esp_err.h"
+
+// Wi-Fi初始化函数
+void take_photo(void);
+
+#endif // CAMERA_H

+ 2 - 2
main/wifi_http.c

@@ -7,8 +7,8 @@
 #include "nvs_flash.h"
 #include "wifi_http.h"
 
-#define DEFAULT_SSID "xxy"
-#define DEFAULT_PWD "123456x-"
+#define DEFAULT_SSID "aplid418"
+#define DEFAULT_PWD "aplid418"
 
 static const char *TAG = "wifi_http";