ESP32-CAM拍照输出RGB565数据,wifi传输到stm32控制tft屏显示拍照图像

ESP32-CAM拍照输出RGB565数据,wifi传输到stm32控制tft屏显示拍照图像

拍照采用安信可的ESP32-CAM,显示屏采用2.2寸,TFT SPI 240x320屏幕,使用stm32f103c8t6核心板连接esp8266-01与ESP32-CAM实现WIFI传输数据,控制显示屏图像。

ESP32-CAM设置为AP模式,此处修改wifi名字与密码

const char *ssid = "601";             //WIFI名字
const char *password = "945738307";   //WIFI密码

摄像头设置,此处修改输出格式与大小

  config.pixel_format = PIXFORMAT_RGB565;   //输出RGB565
  config.frame_size = FRAMESIZE_QVGA;       //320X240
  config.jpeg_quality = 10;                 //10-60,数值越小,jpg图像效果越好
  config.fb_count = 1;

从按下按键ESP32-CAM拍照开始到tft显示完整的320x240图像大约需要5秒左右。

效果图:
请添加图片描述

完整代码下载链接:https://pan.baidu.com/s/1LO9PhiDwUyiI_N5Mq1ne2w
提取码:fyje

  • 11
    点赞
  • 94
    收藏
    觉得还不错? 一键收藏
  • 12
    评论
以下是一个简单的示例代码,演示如何使用ESP32-CAM拍照并将其显示在ST7735显示上。在运行此代码之前,请确保您已正确连接ESP32-CAM和ST7735显示,并已安装必要的库。 ```C++ #include <WiFi.h> #include "esp_camera.h" #include <Adafruit_ST7735.h> // Replace with your network credentials const char* ssid = "your_SSID"; const char* password = "your_PASSWORD"; // Pin definition for ST7735 display #define TFT_CS 15 #define TFT_RST -1 #define TFT_DC 2 #define TFT_MOSI 23 #define TFT_SCLK 18 // Initialize ST7735 display Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST); // Camera pins #define CAM_PIN_CLK 4 #define CAM_PIN_SIOD 13 #define CAM_PIN_SIOC 14 #define CAM_PIN_VSYNC 5 #define CAM_PIN_HREF 27 #define CAM_PIN_PWDN -1 #define CAM_PIN_XCLK 21 #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 33 #define CAM_PIN_D0 32 #define CAM_PIN_RESET -1 // Initialize camera void initCamera() { camera_config_t config; config.ledc_channel = LEDC_CHANNEL_0; config.ledc_timer = LEDC_TIMER_0; config.pin_d0 = CAM_PIN_D0; config.pin_d1 = CAM_PIN_D1; config.pin_d2 = CAM_PIN_D2; config.pin_d3 = CAM_PIN_D3; config.pin_d4 = CAM_PIN_D4; config.pin_d5 = CAM_PIN_D5; config.pin_d6 = CAM_PIN_D6; config.pin_d7 = CAM_PIN_D7; config.pin_xclk = CAM_PIN_XCLK; config.pin_pclk = -1; config.pin_vsync = CAM_PIN_VSYNC; config.pin_href = CAM_PIN_HREF; config.pin_sscb_sda = CAM_PIN_SIOD; config.pin_sscb_scl = CAM_PIN_SIOC; config.pin_pwdn = CAM_PIN_PWDN; config.pin_reset = CAM_PIN_RESET; config.xclk_freq_hz = 20000000; config.pixel_format = PIXFORMAT_JPEG; config.frame_size = FRAMESIZE_SVGA; config.jpeg_quality = 10; config.fb_count = 1; esp_err_t err = esp_camera_init(&config); if (err != ESP_OK) { Serial.printf("Camera init failed with error 0x%x", err); } } void setup() { Serial.begin(115200); // Initialize ST7735 display tft.initR(INITR_BLACKTAB); tft.setRotation(3); // Connect to Wi-Fi WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.println("Connecting to WiFi..."); } // Initialize camera initCamera(); } void loop() { // Take photo camera_fb_t* fb = esp_camera_fb_get(); if (!fb) { Serial.println("Camera capture failed"); return; } // Display photo on ST7735 display tft.fillScreen(ST7735_BLACK); tft.drawRGBBitmap(0, 0, (uint16_t*)fb->buf, fb->width, fb->height); tft.setCursor(0, 0); tft.setTextColor(ST7735_WHITE); tft.setTextSize(2); tft.printf("ESP32-CAM"); // Release memory esp_camera_fb_return(fb); delay(5000); // Wait 5 seconds before taking another photo } ``` 请注意,此示例代码仅在带有ST7735显示ESP32-CAM上进行了测试。如果您的ESP32-CAM具有不同的硬件配置,则可能需要进行适当的修改。
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值