使用NodeMcu-ESP8266点亮SPI接口的1.3寸/2.4寸TFT液晶屏(ST7789)
一、所需硬件清单
(一)NodeMCU-ESP8266开发板,1块
(二)TFT彩色液晶显示屏:2块
彩色液晶屏,简称TFT(ThinFilm Transistor)是指薄膜晶体管的缩写,意即液晶屏上的每个液晶像素点,都是由集成在像素点后面的薄膜晶体管来驱动,从而可以做到高速度、高亮度、高对比度显示屏幕信息,是一类有源矩阵液晶显示设备。是最好的LCD彩色显示设备之一,其效果接近CRT显示器,是笔记本电脑和台式机上的主流显示设备。
(1)1.3寸TFT液晶显示屏模组240×240 IPS高清高亮 SPI串口屏,驱动芯片ST7789
(2)2.4寸TFT液晶显示屏模组SPI串口屏240×320高清宽视角,驱动芯片ST7789
(三)面包板1块,杜邦线若干
二、TFT_eSPI下载,适用于Arduino和PlatformIO 的第三方库
当前最新版本是:TFT_eSPI-2.5.43 ,1) 本地下载(百度网盘,提取码:m63c);(2)Github官网;(3)从Arduino IDE的库管理器标签中,下载TFT_eSPI库。
三、电路连接引脚对应关系
1.3TFT屏 | GND | VCC | SCK | SDA | RESET | DC | BLK |
NodeMCU | GND | 3.3V | D5 | D7 | D4 | D3 | — |
2.4TFT屏 | GND | VCC | SCL | SDA | RESET | A0 | CS | BL |
NodeMCU | GND | 3.3V | D5 | D7 | D4 | D3 |
GND |
D1或3.3V |
特别说明 |
2.4寸屏CS引脚需连接GND,不能连接D8 。否则,有可能出现无法连接烧录的情况,并提示以下错误信息: Connecting…….._____….._____.. A fatal esptool.py error occurred: Failed to connect to ESP8266:Timed out waiting for packet header 。 |
四、修改配置文件
在 TFT_eSPI-2.5.43 库的路径下( X:\****\libraries\TFT_eSPI),打开并修改配置文件User_Setup.h的内容。
(一)对于1.3TFT屏,用以下代码替换User_Setup.h中的全部内容
#define USER_SETUP_INFO "User_Setup"
#define ST7789_DRIVER // Full configuration option, define additional parameters below for this display
#define TFT_WIDTH 240 // ST7789 240 x 240 and 240 x 320
#define TFT_HEIGHT 240 // ST7789 240 x 240
// For NodeMCU - use pin numbers in the form PIN_Dx where Dx is the NodeMCU pin designation
#define TFT_MISO PIN_D6 // Automatically assigned with ESP8266 if not defined
#define TFT_MOSI PIN_D7 // Automatically assigned with ESP8266 if not defined
#define TFT_SCLK PIN_D5 // Automatically assigned with ESP8266 if not defined
#define TFT_CS PIN_D8 // Chip select control pin D8 //*** 2.4寸TFT,8P,320*240, display cs pin is attached to MCU pin GND. //*** 1.3寸TFT,7P, 240*240, this line is not attached any MCU pin.
#define TFT_DC PIN_D3 // Data Command control pin
#define TFT_RST PIN_D4 // Reset pin (could connect to NodeMCU RST, see next line)
//#define TFT_BL PIN_D1 // LED back-light (only for ST7789 with backlight control pin) //*** 2.4寸TFT,8P,320*240, this line is not comment. BL 也可直接3.3V.
//*** 1.3寸TFT,7P, 240*240, this line is comment out.
#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_GFXFF // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts
#define SMOOTH_FONT
#define SPI_FREQUENCY 27000000
#define SPI_READ_FREQUENCY 20000000
#define SPI_TOUCH_FREQUENCY 2500000
(二)对于2.4寸TFT屏,用以下代码替换User_Setup.h中的全部内容
#define USER_SETUP_INFO "User_Setup"
#define ST7789_DRIVER // Full configuration option, define additional parameters below for this display
#define TFT_WIDTH 240 // ST7789 240 x 240 and 240 x 320
#define TFT_HEIGHT 320 // ST7789 240 x 320
// For NodeMCU - use pin numbers in the form PIN_Dx where Dx is the NodeMCU pin designation
#define TFT_MISO PIN_D6 // Automatically assigned with ESP8266 if not defined
#define TFT_MOSI PIN_D7 // Automatically assigned with ESP8266 if not defined
#define TFT_SCLK PIN_D5 // Automatically assigned with ESP8266 if not defined
#define TFT_CS PIN_D8 // Chip select control pin D8 //*** 2.4寸TFT,8P,320*240, display cs pin is attached to MCU pin GND. //*** 1.3寸TFT,7P, 240*240, this line is not attached any MCU pin.
#define TFT_DC PIN_D3 // Data Command control pin
#define TFT_RST PIN_D4 // Reset pin (could connect to NodeMCU RST, see next line)
#define TFT_BL PIN_D1 // LED back-light (only for ST7789 with backlight control pin) //*** 2.4寸TFT,8P,320*240, this line is not comment. BL 也可直接3.3V.
//*** 1.3寸TFT,7P, 240*240, this line is comment out.
#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_GFXFF // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts
#define SMOOTH_FONT
#define SPI_FREQUENCY 27000000
#define SPI_READ_FREQUENCY 20000000
#define SPI_TOUCH_FREQUENCY 2500000
五、电路连接展示
(一)1.3寸TFT液晶屏电路实物连接图
(二)2.4寸TFT液晶屏电路实物连接图
六、第三方库官方示例视频效果演示
(一)1.3寸TFT液晶屏视频演示
1.3寸TFT液晶显示屏视频演示
(二)2.4寸TFT液晶屏视频演示
2.4寸TFT液晶显示屏(SPI, ST7789)实例演示
作者:ESP8266应用