参考这教程:
使用esp8266点亮福利屏型号st7735的1.44的TFT屏
管脚连接:
我的用的TFT1.44寸ST7735,与NodeMCU针脚接线成功连接
VCC——3V
GND——G
LED——3V
CLK——D5
SDI——D7
RS——D6
RST——D4
CS——D8
这里给出常用的屏幕管脚定义
以及esp8266nodemcu的管脚定义,协助理解接线:
RS——D6
CS——D8
RST——D4
是因为在Arduino\libraries\TFT_eSPI\下的User_Setup.h中有定义:
遇到的错误:
- 报错找不到 <TJpg_Decoder.h> 这个库,网上找了一番没有相关的帖子,自己找到这个网站,下载了1.0.7的版本
,解压放到了对应arduino的libraries文件夹下,直接编译通过。
给出测试的demo
//屏幕驱动库
#include <TFT_eSPI.h>
//spi驱动库
#include <SPI.h>
//图片解码库
#include <TJpg_Decoder.h>// bilibili的图标
#include "img/bililogo.h"//背景颜色
uint16_t bgColor =0x0000 ;
//线框颜色
uint16_t xkColor= 0xFFFF;
// 上一次刷新时间
int AprevTime = 0;
// 第Anim张图
int Anim = 0;TFT_eSPI tft = TFT_eSPI(); // 引脚请自行配置tft_espi库中的 User_Setup.h文件
TFT_eSprite clk = TFT_eSprite(&tft);bool tft_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t* bitmap)
{if ( y >= tft.height() ) return 0;tft.pushImage(x, y, w, h, bitmap);// Return 1 to decode next blockreturn 1;}void setup() {// put your setup code here, to run once:Serial.begin(9600);tft.begin(); /* TFT init */tft.invertDisplay(0);//反转所有显示颜色:1反转,0正常tft.fillScreen(0x0000);tft.setTextColor(TFT_WHITE, 0x0000);// 设置屏幕显示的旋转角度,参数为:0, 1, 2, 3// 分别代表 0°、90°、180°、270°//根据实际需要旋转tft.setRotation(3); TJpgDec.setJpgScale(1);TJpgDec.setSwapBytes(true);TJpgDec.setCallback(tft_output);tft.fillScreen(0x0000);
// tft.fillRoundRect(0,0,128,128,0,bgColor);//实心矩形//绘制线框tft.drawFastHLine(0,0,128,xkColor);tft.drawFastHLine(0,18,128,xkColor);tft.drawFastHLine(0,106,128,xkColor);tft.drawFastVLine(80,0,18,xkColor);tft.drawFastHLine(0,88,128,xkColor);tft.drawFastVLine(32,88,18,xkColor);tft.drawFastVLine(85,88,18,xkColor);
}void fanspush()
{TJpgDec.drawJpg(1,108,bililogo,sizeof(bililogo));
}void loop() {// put your main code here, to run repeatedly:fanspush();
// myImage();
// imgAnim();
}
对应的.h文件大家可以自己生成参考这个网站
我这也给出
#include <pgmspace.h>
const uint8_t bililogo[] PROGMEM = {
0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01, 0x01, 0x01, 0x00, 0x48, 0x00, 0x48, 0x00, 0x00, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x08, 0x06, 0x06, 0x07, 0x06,
0x05, 0x08, 0x07, 0x07, 0x07, 0x09, 0x09, 0x08, 0x0a, 0x0c, 0x14, 0x0d, 0x0c, 0x0b, 0x0b, 0x0c, 0x19, 0x12, 0x13, 0x0f, 0x14, 0x1d, 0x1a, 0x1f, 0x1e, 0x1d, 0x1a, 0x1c, 0x1c, 0x20,
0x24, 0x2e, 0x27, 0x20, 0x22, 0x2c, 0x23, 0x1c, 0x1c, 0x28, 0x37, 0x29, 0x2c, 0x30, 0x31, 0x34, 0x34, 0x34, 0x1f, 0x27, 0x39, 0x3d, 0x38, 0x32, 0x3c, 0x2e, 0x33, 0x34, 0x32, 0xff,
0xdb, 0x00, 0x43, 0x01, 0x09, 0x09, 0x09, 0x0c, 0x0b, 0x0c, 0x18, 0x0d, 0x0d, 0x18, 0x32, 0x21, 0x1c, 0x21, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32,
0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32,
0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0xff, 0xc0, 0x00, 0x11, 0x08, 0x00, 0x12, 0x00, 0x12, 0x03, 0x01, 0x22, 0x00, 0x02, 0x11, 0x01, 0x03, 0x11, 0x01, 0xff, 0xc4, 0x00,
0x1f, 0x00, 0x00, 0x01, 0x05, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
0xff, 0xc4, 0x00, 0xb5, 0x10, 0x00, 0x02, 0x01, 0x03, 0x03, 0x02, 0x04, 0x03, 0x05, 0x05, 0x04, 0x04, 0x00, 0x00, 0x01, 0x7d, 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21,
0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08, 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0, 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a,
0x16, 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56,
0x57, 0x58, 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x92, 0x93,
0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6,
0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0xf9, 0xfa, 0xff, 0xc4, 0x00, 0x1f, 0x01, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0xff, 0xc4, 0x00, 0xb5, 0x11, 0x00, 0x02, 0x01, 0x02, 0x04, 0x04, 0x03, 0x04, 0x07, 0x05, 0x04, 0x04, 0x00, 0x01, 0x02, 0x77, 0x00, 0x01, 0x02,
0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0, 0x15,
0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34, 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x82, 0x83, 0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 0xa6, 0x9d, 0xae, 0x5e, 0x13, 0x22, 0xbc, 0x7b, 0xd4, 0x16, 0x42, 0x37, 0x7d, 0x0e, 0x46, 0x41, 0xc5, 0x33, 0x42, 0xd1, 0x7c, 0x5d, 0x16, 0xa9, 0xa5, 0xd8, 0x5b, 0x68, 0x7a,
0xe6, 0x9d, 0xa0, 0xad, 0xed, 0xbc, 0xf7, 0x51, 0x5f, 0x3f, 0x99, 0x1c, 0x61, 0x26, 0x57, 0x32, 0x02, 0xc8, 0xa1, 0x30, 0x06, 0x7e, 0x50, 0x09, 0xe7, 0x24, 0xe7, 0x14, 0x01, 0xe6,
0x77, 0xa0, 0xe9, 0xf7, 0xf7, 0x16, 0x57, 0x19, 0x13, 0xdb, 0xca, 0xd1, 0x48, 0x14, 0xe4, 0x06, 0x52, 0x41, 0xc7, 0xe2, 0x28, 0xa7, 0xf8, 0x9d, 0xc6, 0xa1, 0xe2, 0xcd, 0x66, 0xf6,
0xdc, 0x6f, 0x82, 0xe2, 0xfa, 0x79, 0x63, 0x65, 0x3c, 0x32, 0xb3, 0x92, 0x08, 0xfc, 0x0d, 0x14, 0x08, 0x84, 0xcb, 0x24, 0x2d, 0xba, 0x27, 0x68, 0xd8, 0xe3, 0x25, 0x0e, 0x0d, 0x2b,
0x5c, 0xcf, 0x39, 0xdb, 0x34, 0xd2, 0x48, 0xbe, 0x8e, 0xc4, 0x8f, 0xd6, 0x8a, 0x28, 0x01, 0x68, 0xa2, 0x8a, 0x00, 0xff, 0xd9,
};
这里解释一下图片数据定义时的 PROGMEM 关键字,给出官方解释:
#include <pgmspace.h>
const uint8_t bililogo[] PROGMEM = {
0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01, 0x01, 0x01, 0x00, 0x48, 0x00, 0x48, 0x00, 0x00, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x08, 0x06, 0x06, 0x07, 0x06,
0x05, 0x08, 0x07, 0x07, 0x07, 0x09, 0x09, 0x08, 0x0a, 0x0c, 0x14, 0x0d, 0x0c, 0x0b, 0x0b, 0x0c, 0x19, 0x12, 0x13, 0x0f, 0x14, 0x1d, 0x1a, 0x1f, 0x1e, 0x1d, 0x1a, 0x1c, 0x1c, 0x20,
0x24, 0x2e, 0x27, 0x20, 0x22, 0x2c, 0x23, 0x1c, 0x1c, 0x28, 0x37, 0x29, 0x2c, 0x30, 0x31, 0x34, 0x34, 0x34, 0x1f, 0x27, 0x39, 0x3d, 0x38, 0x32, 0x3c, 0x2e, 0x33, 0x34, 0x32, 0xff,
0xdb, 0x00, 0x43, 0x01, 0x09, 0x09, 0x09, 0x0c, 0x0b, 0x0c, 0x18, 0x0d, 0x0d, 0x18, 0x32, 0x21, 0x1c, 0x21, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32,
也就是说告诉mcu(板子)存在FLASH中,而不是SRAM中,这里给出FLASH与SRAM的区别:
参考这个
最后的最后,这个博主的教程我觉得很有用
Arduino+esp8266+1.3寸TFT屏(st7789驱动)显示图片教程