4203浏览
查看: 4203|回复: 8

[ESP8266/ESP32] FireBeetle 2 ESP32-S3 图传手机APP 行空板

[复制链接]
本帖最后由 云天 于 2023-8-22 16:35 编辑

    有机会试用FireBeetle 2 ESP32-S3,我在Arduino IDE安装DFRobot Firebeetle ESP32-S3主板后,示例中有“CameraWebServer”,功能比较强大。本试用项目将结合App inventor2制作手机APP监控画面。使用行空板接收FireBeetle 2 ESP32-S3的拍照画面。
一、安装FireBeetle 2 ESP32-S3
我将使用Arduino IDE对ESP32开发板进行编程。因此,需要安装Arduino IDE以及ESP32附加组件:
FireBeetle 2 ESP32-S3 图传手机APP 行空板图8
二、修改“CameraWebServer”示例

增加电源管理:
#include "DFRobot_AXP313A.h"
DFRobot_AXP313A axp;
axp.enableCameraPower(axp.eOV2640); // 设置摄像头供电
备注:要在原示例中修改
  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. //            You must select partition scheme from the board menu that has at least 3MB APP space.
  9. //            Face Recognition is DISABLED for ESP32 and ESP32-S2, because it takes up from 15
  10. //            seconds to process single frame. Face Detection is ENABLED if PSRAM is enabled as well
  11. // ===================
  12. // Select camera model
  13. // ===================
  14. //#define CAMERA_MODEL_WROVER_KIT // Has PSRAM
  15. //#define CAMERA_MODEL_ESP_EYE // Has PSRAM
  16. //#define CAMERA_MODEL_ESP32S3_EYE // Has PSRAM
  17. //#define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM
  18. //#define CAMERA_MODEL_M5STACK_V2_PSRAM // M5Camera version B Has PSRAM
  19. //#define CAMERA_MODEL_M5STACK_WIDE // Has PSRAM
  20. //#define CAMERA_MODEL_M5STACK_ESP32CAM // No PSRAM
  21. //#define CAMERA_MODEL_M5STACK_UNITCAM // No PSRAM
  22. //#define CAMERA_MODEL_AI_THINKER // Has PSRAM
  23. //#define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM
  24. //#define CAMERA_MODEL_XIAO_ESP32S3 // Has PSRAM
  25. // ** Espressif Internal Boards **
  26. //#define CAMERA_MODEL_ESP32_CAM_BOARD
  27. //#define CAMERA_MODEL_ESP32S2_CAM_BOARD
  28. //#define CAMERA_MODEL_ESP32S3_CAM_LCD
  29. #define CAMERA_MODEL_DFRobot_FireBeetle2_ESP32S3 // Has PSRAM
  30. //#define CAMERA_MODEL_DFRobot_Romeo_ESP32S3 // Has PSRAM
  31. #include "camera_pins.h"
  32. #include "DFRobot_AXP313A.h"
  33. DFRobot_AXP313A axp;
  34. // ===========================
  35. // Enter your WiFi credentials
  36. // ===========================
  37. const char* ssid = "*******";
  38. const char* password = "********";
  39. void startCameraServer();
  40. void setupLedFlash(int pin);
  41. void setup() {
  42.   Serial.begin(115200);
  43.   Serial.setDebugOutput(true);
  44.   Serial.println();
  45.     while (axp.begin() != 0)
  46.   {
  47.     Serial.println("init error");
  48.     delay(1000);
  49.   }
  50. axp.enableCameraPower(axp.eOV2640); // 设置摄像头供电
  51.   camera_config_t config;
  52.   config.ledc_channel = LEDC_CHANNEL_0;
  53.   config.ledc_timer = LEDC_TIMER_0;
  54.   config.pin_d0 = Y2_GPIO_NUM;
  55.   config.pin_d1 = Y3_GPIO_NUM;
  56.   config.pin_d2 = Y4_GPIO_NUM;
  57.   config.pin_d3 = Y5_GPIO_NUM;
  58.   config.pin_d4 = Y6_GPIO_NUM;
  59.   config.pin_d5 = Y7_GPIO_NUM;
  60.   config.pin_d6 = Y8_GPIO_NUM;
  61.   config.pin_d7 = Y9_GPIO_NUM;
  62.   config.pin_xclk = XCLK_GPIO_NUM;
  63.   config.pin_pclk = PCLK_GPIO_NUM;
  64.   config.pin_vsync = VSYNC_GPIO_NUM;
  65.   config.pin_href = HREF_GPIO_NUM;
  66.   config.pin_sccb_sda = SIOD_GPIO_NUM;
  67.   config.pin_sccb_scl = SIOC_GPIO_NUM;
  68.   config.pin_pwdn = PWDN_GPIO_NUM;
  69.   config.pin_reset = RESET_GPIO_NUM;
  70.   config.xclk_freq_hz = 20000000;
  71.   config.frame_size = FRAMESIZE_UXGA;
  72.   config.pixel_format = PIXFORMAT_JPEG; // for streaming
  73.   //config.pixel_format = PIXFORMAT_RGB565; // for face detection/recognition
  74.   config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
  75.   config.fb_location = CAMERA_FB_IN_PSRAM;
  76.   config.jpeg_quality = 12;
  77.   config.fb_count = 1;
  78.   
  79.   // if PSRAM IC present, init with UXGA resolution and higher JPEG quality
  80.   //                      for larger pre-allocated frame buffer.
  81.   if(config.pixel_format == PIXFORMAT_JPEG){
  82.     if(psramFound()){
  83.       config.jpeg_quality = 10;
  84.       config.fb_count = 2;
  85.       config.grab_mode = CAMERA_GRAB_LATEST;
  86.     } else {
  87.       // Limit the frame size when PSRAM is not available
  88.       config.frame_size = FRAMESIZE_SVGA;
  89.       config.fb_location = CAMERA_FB_IN_DRAM;
  90.     }
  91.   } else {
  92.     // Best option for face detection/recognition
  93.     config.frame_size = FRAMESIZE_240X240;
  94. #if CONFIG_IDF_TARGET_ESP32S3
  95.     config.fb_count = 2;
  96. #endif
  97.   }
  98. #if defined(CAMERA_MODEL_ESP_EYE)
  99.   pinMode(13, INPUT_PULLUP);
  100.   pinMode(14, INPUT_PULLUP);
  101. #endif
  102.   // camera init
  103.   esp_err_t err = esp_camera_init(&config);
  104.   if (err != ESP_OK) {
  105.     Serial.printf("Camera init failed with error 0x%x", err);
  106.     return;
  107.   }
  108.   sensor_t * s = esp_camera_sensor_get();
  109.   // initial sensors are flipped vertically and colors are a bit saturated
  110.   if (s->id.PID == OV3660_PID) {
  111.     s->set_vflip(s, 1); // flip it back
  112.     s->set_brightness(s, 1); // up the brightness just a bit
  113.     s->set_saturation(s, -2); // lower the saturation
  114.   }
  115.   // drop down frame size for higher initial frame rate
  116.   if(config.pixel_format == PIXFORMAT_JPEG){
  117.     s->set_framesize(s, FRAMESIZE_QVGA);
  118.   }
  119. #if defined(CAMERA_MODEL_M5STACK_WIDE) || defined(CAMERA_MODEL_M5STACK_ESP32CAM)
  120.   s->set_vflip(s, 1);
  121.   s->set_hmirror(s, 1);
  122. #endif
  123. #if defined(CAMERA_MODEL_ESP32S3_EYE)
  124.   s->set_vflip(s, 1);
  125. #endif
  126. // Setup LED FLash if LED pin is defined in camera_pins.h
  127. #if defined(LED_GPIO_NUM)
  128.   setupLedFlash(LED_GPIO_NUM);
  129. #endif
  130.   WiFi.begin(ssid, password);
  131.   WiFi.setSleep(false);
  132.   while (WiFi.status() != WL_CONNECTED) {
  133.     delay(500);
  134.     Serial.print(".");
  135.   }
  136.   Serial.println("");
  137.   Serial.println("WiFi connected");
  138.   startCameraServer();
  139.   Serial.print("Camera Ready! Use 'http://");
  140.   Serial.print(WiFi.localIP());
  141.   Serial.println("' to connect");
  142. }
  143. void loop() {
  144.   // Do nothing. Everything is done in another task by the web server
  145.   delay(10000);
  146. }
复制代码
三、制作手机APP
1.组件设计
FireBeetle 2 ESP32-S3 图传手机APP 行空板图9
2.逻辑设计
FireBeetle 2 ESP32-S3 图传手机APP 行空板图10
3.测试
FireBeetle 2 ESP32-S3 图传手机APP 行空板图11

FireBeetle 2 ESP32-S3 图传手机APP 行空板图12
4.演示视频

四、行空板接收拍照画面
1.修改“CameraWebServer”示例
  1. #include "esp_camera.h"
  2. #include <WiFi.h>
  3. #include <HTTPClient.h>
  4. // 用于上传照片的服务器地址,行空板IP地址
  5. const char *serverName = "http://192.168.31.71:9000/upload";
  6. //
  7. // WARNING!!! PSRAM IC required for UXGA resolution and high JPEG quality
  8. //            Ensure ESP32 Wrover Module or other board with PSRAM is selected
  9. //            Partial images will be transmitted if image exceeds buffer size
  10. //
  11. //            You must select partition scheme from the board menu that has at least 3MB APP space.
  12. //            Face Recognition is DISABLED for ESP32 and ESP32-S2, because it takes up from 15
  13. //            seconds to process single frame. Face Detection is ENABLED if PSRAM is enabled as well
  14. // ===================
  15. // Select camera model
  16. // ===================
  17. #define PWDN_GPIO_NUM -1
  18. #define RESET_GPIO_NUM -1
  19. #define XCLK_GPIO_NUM 45
  20. #define SIOD_GPIO_NUM 1
  21. #define SIOC_GPIO_NUM 2
  22. #define Y9_GPIO_NUM 48
  23. #define Y8_GPIO_NUM 46
  24. #define Y7_GPIO_NUM 8
  25. #define Y6_GPIO_NUM 7
  26. #define Y5_GPIO_NUM 4
  27. #define Y4_GPIO_NUM 41
  28. #define Y3_GPIO_NUM 40
  29. #define Y2_GPIO_NUM 39
  30. #define VSYNC_GPIO_NUM 6
  31. #define HREF_GPIO_NUM 42
  32. #define PCLK_GPIO_NUM 5
  33. #define ONBOARD_KEY 47 // 板载按钮
  34. #define ONBOARD_LED 21 // 板载 LED
  35. volatile bool buttonPressed = false; // 按钮下降沿中断标志位
  36. #define CAMERA_MODEL_DFRobot_FireBeetle2_ESP32S3 // Has PSRAM
  37. //#define CAMERA_MODEL_DFRobot_Romeo_ESP32S3 // Has PSRAM
  38. #include "camera_pins.h"
  39. #include "DFRobot_AXP313A.h"
  40. DFRobot_AXP313A axp;
  41. // ===========================
  42. // Enter your WiFi credentials
  43. // ===========================
  44. const char *ssid = "********";
  45. const char *password = "*************";
  46. void startCameraServer();
  47. void setup()
  48. {
  49.   pinMode(ONBOARD_KEY, INPUT);
  50.   pinMode(ONBOARD_LED, OUTPUT);
  51.   attachInterrupt(digitalPinToInterrupt(ONBOARD_KEY), buttonInterrupt, FALLING);
  52.   Serial.begin(115200);
  53.   Serial.setDebugOutput(true);
  54.   Serial.println();
  55.   while (axp.begin() != 0)
  56.   {
  57.     Serial.println("init error");
  58.     delay(1000);
  59.   }
  60.   axp.enableCameraPower(axp.eOV2640); // 设置摄像头供电
  61.   camera_config_t config;
  62.   config.ledc_channel = LEDC_CHANNEL_0;
  63.   config.ledc_timer = LEDC_TIMER_0;
  64.   config.pin_d0 = Y2_GPIO_NUM;
  65.   config.pin_d1 = Y3_GPIO_NUM;
  66.   config.pin_d2 = Y4_GPIO_NUM;
  67.   config.pin_d3 = Y5_GPIO_NUM;
  68.   config.pin_d4 = Y6_GPIO_NUM;
  69.   config.pin_d5 = Y7_GPIO_NUM;
  70.   config.pin_d6 = Y8_GPIO_NUM;
  71.   config.pin_d7 = Y9_GPIO_NUM;
  72.   config.pin_xclk = XCLK_GPIO_NUM;
  73.   config.pin_pclk = PCLK_GPIO_NUM;
  74.   config.pin_vsync = VSYNC_GPIO_NUM;
  75.   config.pin_href = HREF_GPIO_NUM;
  76.   config.pin_sscb_sda = SIOD_GPIO_NUM;
  77.   config.pin_sscb_scl = SIOC_GPIO_NUM;
  78.   config.pin_pwdn = PWDN_GPIO_NUM;
  79.   config.pin_reset = RESET_GPIO_NUM;
  80.   config.xclk_freq_hz = 20000000;
  81.   config.frame_size = FRAMESIZE_QVGA;   // 照片分辨率。这里默认为 FRAMESIZE_UXGA
  82.   config.pixel_format = PIXFORMAT_JPEG; // for streaming
  83.   // config.pixel_format = PIXFORMAT_RGB565; // for face detection/recognition
  84.   config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
  85.   config.fb_location = CAMERA_FB_IN_PSRAM;
  86.   config.jpeg_quality = 12; // 63; // 照片质量。这里默认为 12
  87.   config.fb_count = 1;
  88.   /*
  89.   FRAMESIZE_QVGA (320 x 240)
  90.   FRAMESIZE_CIF (352 x 288)
  91.   FRAMESIZE_VGA (640 x 480)
  92.   FRAMESIZE_SVGA (800 x 600)
  93.   FRAMESIZE_XGA (1024 x 768)
  94.   FRAMESIZE_SXGA (1280 x 1024)
  95.   FRAMESIZE_UXGA (1600 x 1200)
  96.   */
  97.   // if PSRAM IC present, init with UXGA resolution and higher JPEG quality
  98.   //                      for larger pre-allocated frame buffer.
  99.   if (config.pixel_format == PIXFORMAT_JPEG)
  100.   {
  101.     if (psramFound())
  102.     {
  103.       config.jpeg_quality = 12; // 63; // 照片质量。这里默认为 10
  104.       config.fb_count = 2;
  105.       config.grab_mode = CAMERA_GRAB_LATEST;
  106.     }
  107.     else
  108.     {
  109.       // Limit the frame size when PSRAM is not available
  110.       config.frame_size = FRAMESIZE_UXGA; // 照片分辨率。这里默认为 FRAMESIZE_SVGA
  111.       config.fb_location = CAMERA_FB_IN_DRAM;
  112.     }
  113.   }
  114.   else
  115.   {
  116.     // Best option for face detection/recognition
  117.     config.frame_size = FRAMESIZE_UXGA; // FRAMESIZE_240X240;
  118. #if CONFIG_IDF_TARGET_ESP32S3
  119.     config.fb_count = 2;
  120. #endif
  121.   }
  122. #if defined(CAMERA_MODEL_ESP_EYE)
  123.   pinMode(13, INPUT_PULLUP);
  124.   pinMode(14, INPUT_PULLUP);
  125. #endif
  126.   // camera init
  127.   esp_err_t err = esp_camera_init(&config);
  128.   if (err != ESP_OK)
  129.   {
  130.     Serial.printf("Camera init failed with error 0x%x", err);
  131.     return;
  132.   }
  133.   sensor_t *s = esp_camera_sensor_get();
  134.   // initial sensors are flipped vertically and colors are a bit saturated
  135.   if (s->id.PID == OV3660_PID)
  136.   {
  137.     s->set_vflip(s, 1);       // flip it back
  138.     s->set_brightness(s, 1);  // up the brightness just a bit
  139.     s->set_saturation(s, -2); // lower the saturation
  140.   }
  141.   // drop down frame size for higher initial frame rate
  142.   if (config.pixel_format == PIXFORMAT_JPEG)
  143.   {
  144.     s->set_framesize(s, FRAMESIZE_QVGA);
  145.   }
  146. #if defined(CAMERA_MODEL_M5STACK_WIDE) || defined(CAMERA_MODEL_M5STACK_ESP32CAM)
  147.   s->set_vflip(s, 1);
  148.   s->set_hmirror(s, 1);
  149. #endif
  150. #if defined(CAMERA_MODEL_ESP32S3_EYE)
  151.   s->set_vflip(s, 1);
  152. #endif
  153.   WiFi.begin(ssid, password);
  154.   WiFi.setSleep(false);
  155.   while (WiFi.status() != WL_CONNECTED)
  156.   {
  157.     delay(500);
  158.     Serial.print(".");
  159.   }
  160.   Serial.println("");
  161.   Serial.println("WiFi connected");
  162.   startCameraServer();
  163.   Serial.print("Camera Ready! Use 'http://");
  164.   Serial.print(WiFi.localIP());
  165.   Serial.println("' to connect");
  166. }
  167. void loop()
  168. {
  169.   // Do nothing. Everything is done in another task by the web server
  170.   // delay(10000);
  171.   // 按钮按下后的逻辑
  172.   if (buttonPressed)
  173.   {
  174.     // 拍摄照片
  175.     camera_fb_t *fb = esp_camera_fb_get();
  176.     if (!fb)
  177.     {
  178.       Serial.println("获取摄像头帧缓冲失败");
  179.       return;
  180.     }
  181.     // 建立HTTP客户端
  182.     HTTPClient http;
  183.     // 将照片上传到服务器
  184.     http.begin(serverName);
  185.     http.addHeader("Content-Type", "image/jpeg");
  186.     int httpResponseCode = http.POST(fb->buf, fb->len);
  187.     if (httpResponseCode > 0)
  188.     {
  189.       Serial.printf("照片上传成功,服务器返回代码:%d\n", httpResponseCode);
  190.       // 再闪一下提示上传成功
  191.    
  192.     }
  193.     else
  194.     {
  195.       Serial.printf("照片上传失败,错误代码:%s\n", http.errorToString(httpResponseCode).c_str());
  196.     }
  197.     http.end();
  198.     // 释放帧缓冲
  199.     esp_camera_fb_return(fb);
  200.     // delay(1000); // 等待 1 秒后才可再次拍摄和上传
  201.     buttonPressed = false; // 重置中断标志位
  202.   }
  203. }
  204. void buttonInterrupt()
  205. {
  206.   buttonPressed = true; // 设置下降沿中断标志位
  207. }
复制代码
2.行空板程序
  1. from flask import Flask, request
  2. from unihiker import GUI
  3. u_gui=GUI()
  4. 显图=u_gui.draw_image(image="base.png",h=320,x=0,y=0)
  5. app = Flask(__name__)
  6. @app.route('/upload', methods=['POST'])
  7. def upload():
  8.     try:
  9.         image = request.data
  10.         # 保存照片到指定目录
  11.       
  12.         with open('base.png', 'wb') as f:
  13.             f.write(image)
  14.             f.close()
  15.         显图.config(image="base.png")
  16.         
  17.         return "照片上传成功", 200
  18.     except Exception as e:
  19.         print("照片上传失败:", str(e))
  20.         return "照片上传失败", 500
  21. if __name__ == '__main__':
  22.    
  23.     app.run(host='192.168.31.71', port=9000)
  24.             
  25.         
复制代码
3.测试
FireBeetle 2 ESP32-S3 图传手机APP 行空板图13
4.演示视频

五、
GDI接口
这次的FireBeetle 2 ESP32-S3开发板不仅提供了CAM(Camera)接口,还提供了GDI接口:

FireBeetle 2 ESP32-S3 图传手机APP 行空板图7
1.TFT_eSPI配置
TFT_eSPI、lvgl扩展库安装
FireBeetle 2 ESP32-S3 图传手机APP 行空板图5
FireBeetle 2 ESP32-S3 图传手机APP 行空板图6

2.User_Setup_Select.h头文件控制调用哪个配置文件,User_Setups目录中则包含已经做好预配的多种配置文件。
FireBeetle 2 ESP32-S3 图传手机APP 行空板图2

FireBeetle 2 ESP32-S3 图传手机APP 行空板图1

3.按下图FireBeetle 2 ESP32-S3开发板的GDI说明,修改“Setup70b_ESP32_S3_ILI9341.h”对应的GPIO配置:
FireBeetle 2 ESP32-S3 图传手机APP 行空板图3
FireBeetle 2 ESP32-S3 图传手机APP 行空板图4
  1. #define TFT_CS   18 //     10 or 34 (FSPI CS0)
  2. #define TFT_MOSI 15 //     11 or 35 (FSPI D)
  3. #define TFT_SCLK 17 //     12 or 36 (FSPI CLK)
  4. #define TFT_MISO 16 //     13 or 37 (FSPI Q)
  5. // Use pins in range 0-31
  6. #define TFT_DC    3
  7. #define TFT_RST   38
  8. //#define TOUCH_CS 12 // Optional for touch screen
复制代码
运行示例,正在测试,将摄像头采集的内容显示在屏幕上……







可厉害了  见习技师

发表于 2023-8-23 09:09:59

666666牛逼
回复

使用道具 举报

花生编程  中级技匠

发表于 2023-8-23 21:37:59

厉害厉害
回复

使用道具 举报

花生编程  中级技匠

发表于 2023-8-23 21:39:28

不错,赞!
回复

使用道具 举报

谭周强  中级技师

发表于 2023-8-25 22:13:32

6666牛 厉害呀
回复

使用道具 举报

_深蓝_  高级技师

发表于 2023-9-4 10:15:35

手机app的制作工具是什么?大佬
回复

使用道具 举报

云天  初级技神
 楼主|

发表于 2023-9-4 14:48:13

_深蓝_ 发表于 2023-9-4 10:15
手机app的制作工具是什么?大佬

https://app.wxbit.com/
回复

使用道具 举报

_深蓝_  高级技师

发表于 2023-9-6 14:40:30

云天 发表于 2023-9-4 14:48
https://app.wxbit.com/

谢谢大佬
回复

使用道具 举报

ruihan  学徒

发表于 5 天前

能直接保存到SD卡上么?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail