arduino中TFT_ILI9341触摸屏使用TFT_eSPI库的学习LVGL笔记

1 篇文章 0 订阅
1 篇文章 0 订阅

1.TFT_eSPI\User_Setup.h 配置

#define ILI9341_DRIVER       // Generic driver for common displays
// For ESP32 Dev board (only tested with ILI9341 display)
// The hardware SPI can be mapped to any pins

// #define M5STACK  //这个不要使用 会显示镜像

#define TFT_MISO 19
#define TFT_MOSI 23
#define TFT_SCLK 18
#define TFT_CS   15  // Chip select control pin
#define TFT_DC    2  // Data Command control pin
#define TFT_RST   4  // Reset pin (could connect to RST pin)
#define TFT_BL   22  // LED back-light 这个引脚要接高电平,或在代码中置高电平 否则黑屏不显示
#define TOUCH_CS 21  // Chip select pin (T_CS) of touch screen 有触摸屏时这个要设置


#define LOAD_GLCD   // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
#define LOAD_FONT2  // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
#define LOAD_FONT4  // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
#define LOAD_FONT6  // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
#define LOAD_FONT7  // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:-.
#define LOAD_FONT8  // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
//#define LOAD_FONT8N // Font 8. Alternative to Font 8 above, slightly narrower, so 3 digits fit a 160 pixel TFT
#define LOAD_GFXFF  // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts

// Comment out the #define below to stop the SPIFFS filing system and smooth font code being loaded
// this will save ~20kbytes of FLASH
#define SMOOTH_FONT


#define SPI_FREQUENCY  27000000


// Optional reduced SPI frequency for reading TFT
#define SPI_READ_FREQUENCY  20000000

// The XPT2046 requires a lower SPI clock rate of 2.5MHz so we define that here:
#define SPI_TOUCH_FREQUENCY  2500000



2.触摸屏和显示座标不一致的可能问题解决

a.如果使用触摸屏 在使用或更换tft.setRotation(X);设置时,必先校正触摸屏

校正触摸屏方法:

1打开.pio\libdeps\esp32dev\TFT_eSPI\examples\Generic\Touch_calibrate\Touch_calibrate.ino

2.在setup()中运行其中的  touch_calibrate();按提示箭头点击就可校正屏幕,然后就会得到类似

 uint16_t calData[5] = { 286, 3534, 283, 3600, 6 };

  tft.setTouch(calData);

把上面代码放在setup()中.

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,我会为您讲解在Arduino使用TFT_eSPI编程驱动LCD显示的实验过程,以下是详细步骤: 1. 准备材料 你需要准备以下材料: - Arduino开发板 - 2.4寸TFT LCD屏幕 - 杜邦线 - 电位器 - 4.7K电阻 2. 连接电路 将LCD屏幕连接到Arduino开发板上,具体如下: - 将LCD屏幕的VCC接到Arduino的3.3V引脚上 - 将LCD屏幕的GND接到Arduino的GND引脚上 - 将LCD屏幕的CS引脚接到Arduino的D10引脚上 - 将LCD屏幕的DC引脚接到Arduino的D9引脚上 - 将LCD屏幕的MOSI引脚接到Arduino的D11引脚上 - 将LCD屏幕的SCK引脚接到Arduino的D13引脚上 - 将LCD屏幕的RST引脚接到Arduino的D8引脚上 - 将电位器的间引脚接到LCD屏幕的A0引脚上,将电位器的两个端口接到GND和3.3V引脚上,用来控制屏幕亮度 3. 安装TFT_eSPIArduino IDE打开“工具”菜单,选择“管理”,搜索TFT_eSPI并安装。 4. 编写程序 以下是一个简单的程序,用于在LCD屏幕上显示一些文本: ```c++ #include <TFT_eSPI.h> TFT_eSPI tft = TFT_eSPI(); void setup() { tft.begin(); tft.setRotation(1); // 设置屏幕方向 tft.fillScreen(TFT_BLACK); // 填充黑色背景 tft.setTextColor(TFT_WHITE); // 设置字体颜色 tft.setTextSize(2); // 设置字体大小 tft.setCursor(0, 0); // 设置文本位置 tft.println("Hello, World!"); // 显示文本 } void loop() { } ``` 5. 上传程序 将程序上传到Arduino开发板上。 6. 查看LCD屏幕显示 在Arduino开发板上加电,等待程序启动后即可在LCD屏幕上看到显示的文本。 以上就是在Arduino使用TFT_eSPI编程驱动LCD显示的实验过程。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值