Arduino ST7789 240*240 1.3寸 TFT —— 飞升之高效率显示驱动篇

昨天的屏幕到了,也用之前“发现的”Arduino-ST7789-Library“专用驱动库”进行了点亮操作,但总是感觉屏幕显示的效率差强人意。因为在做TFT屏幕选型的时候有了解Arduino生态下各种屏幕的驱动支持情况,发现一个感觉像“大神”一样的库:GFX Library For Arduino。
我买的屏幕是ST7789驱动,想着用专用的,应该不会错,就先有了上一篇的介绍。But, Sometimes, 专用的不一定完全合脚。

先来剧透下惊掉下巴的结果:GFX For Arduino以8倍效率的提升吊打“专用驱动”!!!

点击查看 【弱鸡版专用库介绍】,你看了这个可能会对背景更了解一些,顺便“专用库”的安装方式也不是通过Arduino库管理器进行的,是手动的!是手动的!是手动的!这篇文章也有介绍如何手动安装,大神可以略过…

一、简单介绍下 GFX Library For Arduino

1. 驱动库概述

GitHub地址
作者:Moon On Our Nation (貌似住在Hong Kong)。感谢作者的分享,开源伟大!
作者在著名的3D素材分享社区 Thingiverse,也有很优秀的作品,大家感兴趣可以去瞅瞅。作者Thingiverse主页

言归正传,先贴一张镇楼图(之前忽略了,我的错- -!):
在这里插入图片描述
这应该是作者对几种比较流行的驱动框架做的性能测试对比,我们可以看出来,还是很有优势的。
同时,支持的开发板也比较丰富,例如:

  • Arduino Nana
  • Arduino Nano BLE 33
  • Arduino Pro Micro
  • ESP8266 Series
  • ESP32 Series
  • Raspberry Pi Pico
  • rtlduino
  • WeAct BlackPill V2.0 (BlackPill F411CE)

支持的屏幕驱动:

  • GC9A01 round display 240x240
  • HX8347C 240x320
  • HX8347D 240x320
  • HX8352C 240x400
  • HX8357A 320x480 (currently only portrait works, i.e. rotation 0 and 2)
  • HX8357B (9-bit SPI) 320x480
  • ILI9225 176x220
  • ILI9341 240x320
  • ILI9341 (8-bit Parallel) 240x320
  • ILI9342 320x240
  • ILI9481 320x480 (18 bit color)
  • ILI9486 320x480 (18 bit color)
  • ILI9488 320x480 (3 bit color with canvas)
  • ILI9488 320x480 (18 bit color)
  • ILI9806 (8-bit/16-bit Parallel) 480x854
  • JBT6K71 (8-bit Parallel) 240x320
  • NT35310 320x480
  • NT35510 (8-bit/16-bit Parallel) 480x800
  • NT39125 (8-bit/16-bit Parallel) 240x376
  • R61529 (8-bit/16-bit Parallel) 320x480
  • SEPS525 160x128
  • SSD1283A 130x130
  • SSD1331 96x64
  • SSD1351 128x128
  • SSD1351 128x96
  • ST7735 128x160 (various tabs)
  • ST7735 128x128 (various tabs)
  • ST7735 80x160
  • ST7789 TTGO T-Display 135x240
  • ST7789 240x240
  • ST7789 TTGO T-Watch 240x240
  • ST7789 round corner display 240x280
  • ST7789 240x320
  • ST7796 320x480
    其他详细内容感兴趣的朋友可以去GitHub上项目主页查看。

2. 安装方式

打开Arduino库管理器,输入“GFX Library For Arduino”,在结果中找到,选择最新版本,点击安装即可。
在这里插入图片描述

二、试验对比

1.挑战双方介绍

擂台方:Arduino-ST7789-Library
挑战方:GFX Library For Arduino

2. 比武规则

在一块1.3寸驱动ST7789 240*240的TFT屏幕上进行 刷屏上色,并画直线
我们先来看看运行效果:
擂台方

擂台方:实际结束大概耗时32S左右。CSDN单张图片最大5MB,我只截取了15S左右的GIF。我在下面附一张它运行完后的图片吧
在这里插入图片描述

挑战方

挑战方 :耗时大概4S左右
看上面的结果,还是满震惊的,8倍左右的差距啊。

3.接线说明

首先说一下引脚接线,和上一篇略有区别。本篇两种驱动都采取以下的接线方式,方便测试:

屏幕引脚Arduino引脚说明
GNDGND接地
VCC5V电源
SCL13时钟线
SDA11数据线
RES7复位
DC8命令控制
BLK6背光

基本上按照擂台方的库文件默认定义来搭线。定义在 Arduino_GFX_Library.h 头文件内,因为我用的开发板是Arduino UNO,参考下图:
在这里插入图片描述
注:您也可以根据自己的实际需要去修改这个头文件里面的定义。

4. 代码验证

擂台方代码:


#include <Adafruit_GFX.h>    // Core graphics library by Adafruit
#include <Arduino_ST7789.h> // Hardware-specific library for ST7789 (with or without CS pin)
#include <SPI.h>

#define TFT_DC    8
#define TFT_RST   7  //9 
#define TFT_CS    9  //10 // only for displays with CS pin
#define TFT_MOSI  11   // for hardware SPI data pin (all of available pins)
#define TFT_SCLK  13   // for hardware SPI sclk pin (all of available pins)

#define w 240
#define h 240


Arduino_ST7789 tft = Arduino_ST7789(TFT_DC, TFT_RST, TFT_MOSI, TFT_SCLK, TFT_CS); //for display with CS pin

static inline uint32_t micros_start() __attribute__((always_inline));
static inline uint32_t micros_start()
{
  uint8_t oms = millis();
  while ((uint8_t)millis() == oms)
    ;
  return micros();
}


void setup(){
  Serial.begin(9600);
  tft.init(w, h);
}

void loop(){
  uint32_t start = micros_start();

  tft.fillScreen(BLACK);
  testLines();
  
  uint32_t usecLines = micros() - start;
  tft.setCursor(0, 20);
  tft.setTextSize(3);
  tft.setTextColor(RED);
  tft.println("Cost Time:");

  tft.setCursor(0, 50);
  tft.setTextSize(4);
  tft.setTextColor(RED);
  tft.println(usecLines);

  delay(60 * 1000L);
}

int32_t testLines()
{
  uint32_t start;
  int32_t x1, y1, x2, y2;

  start = micros_start();

  x1 = y1 = 0;
  y2 = h - 1;
  for (x2 = 0; x2 < w; x2 += 6)
  {
    tft.drawLine(x1, y1, x2, y2, BLUE);
  }
#ifdef ESP8266
    yield(); // avoid long run triggered ESP8266 WDT restart
#endif

  x2 = w - 1;
  for (y2 = 0; y2 < h; y2 += 6)
  {
    tft.drawLine(x1, y1, x2, y2, BLUE);
  }
#ifdef ESP8266
    yield(); // avoid long run triggered ESP8266 WDT restart
#endif

  x1 = w - 1;
  y1 = 0;
  y2 = h - 1;
  for (x2 = 0; x2 < w; x2 += 6)
  {
    tft.drawLine(x1, y1, x2, y2, BLUE);
  }
#ifdef ESP8266
    yield(); // avoid long run triggered ESP8266 WDT restart
#endif

  x2 = 0;
  for (y2 = 0; y2 < h; y2 += 6)
  {
    tft.drawLine(x1, y1, x2, y2, BLUE);
  }
#ifdef ESP8266
    yield(); // avoid long run triggered ESP8266 WDT restart
#endif

  x1 = 0;
  y1 = h - 1;
  y2 = 0;
  for (x2 = 0; x2 < w; x2 += 6)
  {
    tft.drawLine(x1, y1, x2, y2, BLUE);
  }
#ifdef ESP8266
    yield(); // avoid long run triggered ESP8266 WDT restart
#endif

  x2 = w - 1;
  for (y2 = 0; y2 < h; y2 += 6)
  {
    tft.drawLine(x1, y1, x2, y2, BLUE);
  }
#ifdef ESP8266
    yield(); // avoid long run triggered ESP8266 WDT restart
#endif

  x1 = w - 1;
  y1 = h - 1;
  y2 = 0;
  for (x2 = 0; x2 < w; x2 += 6)
  {
    tft.drawLine(x1, y1, x2, y2, BLUE);
  }
#ifdef ESP8266
    yield(); // avoid long run triggered ESP8266 WDT restart
#endif

  x2 = 0;
  for (y2 = 0; y2 < h; y2 += 6)
  {
    tft.drawLine(x1, y1, x2, y2, BLUE);
  }
#ifdef ESP8266
    yield(); // avoid long run triggered ESP8266 WDT restart
#endif

  return micros() - start;
}

挑战方代码:

#include <Arduino_GFX_Library.h>

int32_t w, h;

/* More dev device declaration: https://github.com/moononournation/Arduino_GFX/wiki/Dev-Device-Declaration */
#if defined(DISPLAY_DEV_KIT)
Arduino_GFX *gfx = create_default_Arduino_GFX();
#else /* !defined(DISPLAY_DEV_KIT) */

/* More data bus class: https://github.com/moononournation/Arduino_GFX/wiki/Data-Bus-Class */
Arduino_DataBus *bus = create_default_Arduino_DataBus();

/* More display class: https://github.com/moononournation/Arduino_GFX/wiki/Display-Class */
Arduino_GFX *gfx = new Arduino_ST7789(bus, TFT_RST, 2 /* rotation */, true /* IPS */, 240 /* width */, 240 /* height */, 0 /* col offset 1 */, 80 /* row offset 1 */);

#endif /* !defined(DISPLAY_DEV_KIT) */

static inline uint32_t micros_start() __attribute__((always_inline));
static inline uint32_t micros_start()
{
  uint8_t oms = millis();
  while ((uint8_t)millis() == oms)
    ;
  return micros();
}


void setup(){
  Serial.begin(9600);
  gfx->begin();
  w = gfx->width();
  h = gfx->height();

  #ifdef TFT_BL
    pinMode(TFT_BL, OUTPUT);
    digitalWrite(TFT_BL, HIGH);
  #endif
}

void loop(){
  uint32_t start = micros_start();

  gfx->fillScreen(BLACK);
  testLines();
  
  uint32_t usecLines = micros() - start;

  gfx->setCursor(0, 20);
  gfx->setTextSize(3);
  gfx->setTextColor(RED);
  gfx->println(F("Cost Time:"));

  gfx->setCursor(0, 50);
  gfx->setTextSize(4);
  gfx->setTextColor(RED);
  gfx->println(usecLines);

  delay(60 * 1000L);
}

int32_t testLines()
{
  uint32_t start;
  int32_t x1, y1, x2, y2;

  start = micros_start();

  x1 = y1 = 0;
  y2 = h - 1;
  for (x2 = 0; x2 < w; x2 += 6)
  {
    gfx->drawLine(x1, y1, x2, y2, BLUE);
  }
#ifdef ESP8266
    yield(); // avoid long run triggered ESP8266 WDT restart
#endif

  x2 = w - 1;
  for (y2 = 0; y2 < h; y2 += 6)
  {
    gfx->drawLine(x1, y1, x2, y2, BLUE);
  }
#ifdef ESP8266
    yield(); // avoid long run triggered ESP8266 WDT restart
#endif

  x1 = w - 1;
  y1 = 0;
  y2 = h - 1;
  for (x2 = 0; x2 < w; x2 += 6)
  {
    gfx->drawLine(x1, y1, x2, y2, BLUE);
  }
#ifdef ESP8266
    yield(); // avoid long run triggered ESP8266 WDT restart
#endif

  x2 = 0;
  for (y2 = 0; y2 < h; y2 += 6)
  {
    gfx->drawLine(x1, y1, x2, y2, BLUE);
  }
#ifdef ESP8266
    yield(); // avoid long run triggered ESP8266 WDT restart
#endif

  x1 = 0;
  y1 = h - 1;
  y2 = 0;
  for (x2 = 0; x2 < w; x2 += 6)
  {
    gfx->drawLine(x1, y1, x2, y2, BLUE);
  }
#ifdef ESP8266
    yield(); // avoid long run triggered ESP8266 WDT restart
#endif

  x2 = w - 1;
  for (y2 = 0; y2 < h; y2 += 6)
  {
    gfx->drawLine(x1, y1, x2, y2, BLUE);
  }
#ifdef ESP8266
    yield(); // avoid long run triggered ESP8266 WDT restart
#endif

  x1 = w - 1;
  y1 = h - 1;
  y2 = 0;
  for (x2 = 0; x2 < w; x2 += 6)
  {
    gfx->drawLine(x1, y1, x2, y2, BLUE);
  }
#ifdef ESP8266
    yield(); // avoid long run triggered ESP8266 WDT restart
#endif

  x2 = 0;
  for (y2 = 0; y2 < h; y2 += 6)
  {
    gfx->drawLine(x1, y1, x2, y2, BLUE);
  }
#ifdef ESP8266
    yield(); // avoid long run triggered ESP8266 WDT restart
#endif

  return micros() - start;
}

感兴趣的朋友可以将代码烧录到您的开发板实际验证下。

  • 19
    点赞
  • 94
    收藏
    觉得还不错? 一键收藏
  • 23
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值