【2024 DigiKey创意大赛】+便携式红外智能吸烟器+ESP32C6驱动1.54寸st7789屏幕
<div>【2024 DigiKey创意大赛】+便携式红外智能吸烟器+ESP32C6驱动1.54寸st7789屏幕</div><div>想先用屏幕来显示MLX90640热成像传感器的图像,在这期间我遇到了两个很棘手的问题</div>
<div>1是platformio不支持esp32-c6-devkitc-1板子使用arduino的开发方式</div>
<div>2是arduino的TFT_eSPI库st7789库都不支持esp32c6显示(我看论坛有人分享了用st7789库来显示的教程)我尝试了,但还是用不了</div>
<div>问题1解决方法</div>
<div><a href="https://blog.csdn.net/qq_56040798/article/details/139458530">esp32-c6使用教程wifi(espidf修改成arduino)附带代码websocket,舵机,点灯【2024年】-CSDN博客</a></div>
<div>参考这篇文章修改platfprmio.ini配置</div>
<div>第一步选择c6开发板,这里默认读者都有pio开发经验,不懂的可以去看看教程,大部分都是卡在下载esp32的包,我建议是网上电脑不关机,新建工程,第二天早上再看,如果还在转圈圈初始化就重新新建一次一般就可以了</div>
<div></div>
<div>Pio中esp32c6只有espidf的开发方式,这里不急,先新建完工程</div>
<div></div>
<div>对.ini配置文件进行编辑</div>
<div></div>
<div>替换内容为下列代码</div>
<div>
<pre>
<code>; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
platform = https://github.com/sgryphon/platform-espressif32.git
board = esp32-c6-devkitc-1
board_frameworks =
espidf
arduino
board_build.variant = esp32c6
framework = arduino
upload_speed = 921600
monitor_speed = 115200
monitor_filters =
direct
platform_packages =
framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#master
platformio/framework-arduinoespressif32-libs @ https://github.com/espressif/esp32-arduino-libs.git#idf-release/v5.1
build_flags =
-D CONFIG_ARDUHAL_LOG_COLORS=1
-D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO</code></pre>
<p> </p>
</div>
<div>再把main.c文件改为main.cpp</div>
<div></div>
<div>在main函数中打印下面的代码测试彩灯点亮</div>
<div>
<pre>
<code>#include <Arduino.h>
#include <WiFi.h>
#include <WiFiMulti.h>
#include <WiFiClientSecure.h>
#include <SPI.h>
#include <FS.h>
#include "SPIFFS.h"
void setup() {
Serial.begin(115200); // 初始化串口通信
delay(1000); // 等待串口初始化
}
void loop() {
log_i("hello world");
rgbLedWrite(RGB_BUILTIN, 255, 0, 0); //设置显示颜色为红色
delay(500);
rgbLedWrite(RGB_BUILTIN, 255, 165, 0);
delay(500);
rgbLedWrite(RGB_BUILTIN, 255, 255, 0);
delay(500);
rgbLedWrite(RGB_BUILTIN, 0, 255, 0);
delay(500);
rgbLedWrite(RGB_BUILTIN, 0, 127, 255);
delay(500);
rgbLedWrite(RGB_BUILTIN, 0, 0, 255);
delay(500);
rgbLedWrite(RGB_BUILTIN, 139, 0, 255);
delay(500);
}</code></pre>
<p> </p>
</div>
<div>彩灯点亮即可完成esp32c6在pio中使用arduino开发</div>
<div>我发现的一些bug是在编译中经常会遇到头文件找不到的报错</div>
<div>
<pre>
<code>#include <WiFiMulti.h>
#include <WiFiClientSecure.h>
#include <SPI.h>
#include <FS.h>
#include "SPIFFS.h"</code></pre>
<p> </p>
</div>
<div>我在main文件开头手动include即可编译成功,这个问题我找到的解读是选择工程属于espidf于arduino环境混开发,在espidf中不会去编译arduino的spi库等,需要在main函数中手动inculude,否则在运行一些arduino的库会报错很多arduino的头文件找不到</div>
<div>解决了开发环境,下一步就是点亮屏幕了</div>
<div>问题2解决方法</div>
<div>我在github上的TFT_eSPI仓库找有没有类似的不过,发现有个哥们分享了他的方法,但还没被并入正式版本</div>
<div></div>
<div>链接如下:</div>
<div><a href="https://github.com/mboehmerm/Three-IPS-Displays-with-ST7789-170x320-240x280-240x320/tree/main/ESP32_C6">Three-IPS-Displays-with-ST7789-170x320-240x280-240x320/ESP32_C6 at main · mboehmerm/Three-IPS-Displays-with-ST7789-170x320-240x280-240x320 (github.com)</a></div>
<div>我尝试了这个办法,他成功生效了</div>
<div></div>
<div>替换TFT_eSPI库的这四个文件,这个大佬针对esp32c6和esp32h2做了视频优化,亲测有用</div>
<div>下面是小白详细教程</div>
<div></div>
<div>安装成功后</div>
<div></div>
<div>找到这四个文件,替换为下面网站的代码(对着名称替换)</div>
<div>TFT_eSPI_ESP32_C3.c替换为下面网站的代码</div>
<div><a href="https://github.com/mboehmerm/Three-IPS-Displays-with-ST7789-170x320-240x280-240x320/blob/main/ESP32_C6/Arduino/libraries/TFT_eSPI/Processors/TFT_eSPI_ESP32_C3.c">Three-IPS-Displays-with-ST7789-170x320-240x280-240x320/ESP32_C6/Arduino/libraries/TFT_eSPI/Processors/TFT_eSPI_ESP32_C3.c at main · mboehmerm/Three-IPS-Displays-with-ST7789-170x320-240x280-240x320 (github.com)</a></div>
<div>TFT_eSPI_ESP32_C3.h替换为下面网站的代码</div>
<div><a href="https://github.com/mboehmerm/Three-IPS-Displays-with-ST7789-170x320-240x280-240x320/blob/main/ESP32_C6/Arduino/libraries/TFT_eSPI/Processors/TFT_eSPI_ESP32_C3.h">Three-IPS-Displays-with-ST7789-170x320-240x280-240x320/ESP32_C6/Arduino/libraries/TFT_eSPI/Processors/TFT_eSPI_ESP32_C3.h at main · mboehmerm/Three-IPS-Displays-with-ST7789-170x320-240x280-240x320 (github.com)</a></div>
<div>TFT_eSPI.cpp替换为下面网站的代码</div>
<div><a href="https://github.com/mboehmerm/Three-IPS-Displays-with-ST7789-170x320-240x280-240x320/blob/main/ESP32_C6/Arduino/libraries/TFT_eSPI/TFT_eSPI.cpp">Three-IPS-Displays-with-ST7789-170x320-240x280-240x320/ESP32_C6/Arduino/libraries/TFT_eSPI/TFT_eSPI.cpp at main · mboehmerm/Three-IPS-Displays-with-ST7789-170x320-240x280-240x320 (github.com)</a></div>
<div>TFT_eSPI.h替换为下面网站的代码</div>
<div><a href="https://github.com/mboehmerm/Three-IPS-Displays-with-ST7789-170x320-240x280-240x320/blob/main/ESP32_C6/Arduino/libraries/TFT_eSPI/TFT_eSPI.h">Three-IPS-Displays-with-ST7789-170x320-240x280-240x320/ESP32_C6/Arduino/libraries/TFT_eSPI/TFT_eSPI.h at main · mboehmerm/Three-IPS-Displays-with-ST7789-170x320-240x280-240x320 (github.com)</a></div>
<div>这里已经完成了对esp32c6的适配</div>
<div>接下来修改User Setu文件适配屏幕,我用的屏幕是st7789驱动的240*240方屏幕</div>
<div>我在User Setu文件夹创建了一个Setup520_ST7789_ESP32C6_240-240.h文件</div>
<div></div>
<div>内容为下
<pre>
<code>// 用户设置ID
#define USER_SETUP_ID 520
// 驱动程序
#define ST7789_DRIVER // 配置所有寄存器以适应ST7789驱动器
#define TFT_WIDTH 240 // 定义TFT LCD显示器的宽度为240像素
#define TFT_HEIGHT 240 // 定义TFT LCD显示器的高度为240像素
//#define TFT_INVERSION_ON // 启用显示器的颜色反转
//#define TFT_BACKLIGHT_ON 1 // 定义LED背光控制为开启状态
// 颜色顺序(此行被注释掉,表示不使用)
//#define TFT_RGB_ORDER TFT_BGR // 仅适用于240x320分辨率的显示器,设置颜色顺序为BGR
// 引脚ESP32-C6
#define TFT_BL -1 // LED背光控制引脚,-1表示未连接或固定
#define TFT_MISO 20 // MISO引脚,-1表示未连接
#define TFT_MOSI 19 // MOSI引脚,用于SPI通信的数据线
#define TFT_SCLK 21 // SCLK引脚,用于SPI通信的时钟线
#define TFT_CS 18 // 片选引脚,用于选择SPI设备
#define TFT_DC 9 // 数据/命令引脚,用于区分数据或命令
#define TFT_RST -1 // 复位引脚,-1表示未连接或固定
// 字体
#define LOAD_GLCD // 加载GLCD字体
#define LOAD_FONT2 // 加载FONT2字体
#define LOAD_FONT4 // 加载FONT4字体
#define LOAD_FONT6 // 加载FONT6字体
#define LOAD_FONT7 // 加载FONT7字体
#define LOAD_FONT8 // 加载FONT8字体
//#define LOAD_FONT8N // 加载FONT8N字体(此行被注释掉,表示不使用)
#define LOAD_GFXFF // 加载GFX字体库
#define SMOOTH_FONT // 启用字体平滑功能
// 其他选项
//#define SPI_READ_FREQUENCY 20000000 // SPI读取操作的频率(此行被注释掉,表示不使用)
//#define SPI_FREQUENCY 40000000 // 另一个可选的SPI通信频率(此行被注释掉,表示不使用)
#define SPI_FREQUENCY 80000000 // 定义SPI通信的频率为80 MHz</code></pre>
<p> </p>
</div>
<div>再去导入配置文件</div>
<div> </div>
<div>去找个例程</div>
<div>复制粘贴内容到main函数
<pre>
<code>#include <Arduino.h>
#include <WiFi.h>
#include <WiFiMulti.h>
#include <WiFiClientSecure.h>
#include <SPI.h>
#include <FS.h>
#include "SPIFFS.h"
#include <TFT_eSPI.h> // Graphics and font library for ILI9341 driver chip
#define TFT_GREY 0x5AEB // New colour
TFT_eSPI tft = TFT_eSPI(); // Invoke library
void setup(void) {
tft.init();
tft.setRotation(2);
}
void loop() {
// Fill screen with grey so we can see the effect of printing with and without
// a background colour defined
tft.fillScreen(TFT_GREY);
// Set "cursor" at top left corner of display (0,0) and select font 2
// (cursor will move to next line automatically during printing with 'tft.println'
// or stay on the line is there is room for the text with tft.print)
tft.setCursor(0, 0, 2);
// Set the font colour to be white with a black background, set text size multiplier to 1
tft.setTextColor(TFT_WHITE,TFT_BLACK); tft.setTextSize(1);
// We can now plot text on screen using the "print" class
tft.println("Hello World!");
// Set the font colour to be yellow with no background, set to font 7
tft.setTextColor(TFT_YELLOW); tft.setTextFont(7);
tft.println(1234.56);
// Set the font colour to be red with black background, set to font 4
tft.setTextColor(TFT_RED,TFT_BLACK); tft.setTextFont(4);
//tft.println(3735928559L, HEX); // Should print DEADBEEF
// Set the font colour to be green with black background, set to font 4
tft.setTextColor(TFT_GREEN,TFT_BLACK);
tft.setTextFont(4);
tft.println("Groop");
tft.println("I implore thee,");
// Change to font 2
tft.setTextFont(2);
tft.println("my foonting turlingdromes.");
tft.println("And hooptiously drangle me");
tft.println("with crinkly bindlewurdles,");
// This next line is deliberately made too long for the display width to test
// automatic text wrapping onto the next line
tft.println("Or I will rend thee in the gobberwarts with my blurglecruncheon, see if I don't!");
// Test some print formatting functions
float fnumber = 123.45;
// Set the font colour to be blue with no background, set to font 4
tft.setTextColor(TFT_BLUE); tft.setTextFont(4);
tft.print("Float = "); tft.println(fnumber); // Print floating point number
tft.print("Binary = "); tft.println((int)fnumber, BIN); // Print as integer value in binary
tft.print("Hexadecimal = "); tft.println((int)fnumber, HEX); // Print as integer number in Hexadecimal
delay(10000);
}</code></pre>
<p> </p>
</div>
<div>运行即可</div>
<div></div>
<p><!--importdoc--></p>
<p>SPI驱动屏幕,底层驱动程序应该都差不多吧。</p>
wangerxian 发表于 2024-10-17 09:04
SPI驱动屏幕,底层驱动程序应该都差不多吧。
<p>差不多的,只是各家库的一个适配问题,适配速度太慢了</p>
<p> </p>
老杰瑞 发表于 2024-10-17 09:46
差不多的,只是各家库的一个适配问题,适配速度太慢了
<p>适配的太多了,导致找的太慢 </p>
页:
[1]