1.8” TFT フルカラーモジュール(ST7735)の表示が遅いと思ったら

published_with_changes 更新日: event_note 公開日:

labelMemo/Note


ST7735というLCDは、リアルタイムにセンサからもらった数字を表示させているだけなのに、妙に描画が遅いことが気になっていました。こんなものなのかと思いながらも、あれこれあたっているうちに改善策(正しい方法)が分かりました。


利用しているライブラリは、Githubにあるちゃんとしたものなので、これが原因の可能性はありません。

 

不具合状況

処理1行ごとにmilles()コマンドで経過時間を表示させてみると、tft.print("***"); のコマンド1行で160~280msecかかっていました。明らかに何かがおかしいです。


get_ina 3, dto 3, setc 3, setT 3, Pbus 164, Pstr 447, draw_bus 488, draw_shunt 1010

get_ina 4, dto 4, setc 4, setT 4, Pbus 166, Pstr 449, draw_bus 490, draw_shunt 1012

get_ina 4, dto 4, setc 4, setT 4, Pbus 165, Pstr 448, draw_bus 488, draw_shunt 1011

get_ina 4, dto 4, setc 4, setT 4, Pbus 166, Pstr 449, draw_bus 489, draw_shunt 1012

Arduinoフォーラムには同じ悩みの質問が挙がっていましたが、対応者が理解できないらしく無意味なやり取りが繰り返されていました。

Very slow writes to TFT - Using Arduino / Programming Questions - Arduino Forum

Very slow writes to TFT - Using Arduino / Programming Questions - Arduino Forum

I'm using an 160x128 LCD based on the ST7735 connected using hardware SPI to a Nano 33 BLE. And I find all screen operations too slow... As an example, a fillScreen() takes about 1second ! I'm using the Adafruit GFX and ST7735 libraries downloaded from the IDE library manager. What can I try ?

原因

ST7735ライブラリの書き方が原因でした。
INA219とST7735がセットになったスケッチをどこからか持ってきたのですが、そのスケッチはI2C通信のSLCKとMOSIも定義する内容で、これが原因でした。


#include <Adafruit_INA219.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <SPI.h>

#define TFT_CS    10
#define TFT_RST   9
#define TFT_DC    8
#define TFT_SCLK  13
#define TFT_MOSI  11

Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);


対策

9,10行目を削除して、12行目からSCLKとMOSIの記述をなくすことが対策です。ST7735ライブラリのサンプルスケッチは次のようになっています。


#include <Adafruit_INA219.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <SPI.h>

// Declare pins for the display:
#define TFT_CS     10
#define TFT_RST    9  // You can also connect this to the Arduino reset in which case, set this #define pin to -1!
#define TFT_DC     8
// The rest of the pins are pre-selected as the default hardware SPI for Arduino Uno (SCK = 13 and SDA = 11)

// Create display:
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);


結果



tft.print("***"); のコマンド1行にかかる時間は15~24msecと改善できました。

get_ina 3, dto 3, setc 3, setT 3, Pbus 18, Pstr 42, draw_bus 45, draw_shunt 91

get_ina 3, dto 3, setc 4, setT 4, Pbus 18, Pstr 42, draw_bus 46, draw_shunt 91

get_ina 4, dto 4, setc 4, setT 4, Pbus 18, Pstr 43, draw_bus 46, draw_shunt 91

get_ina 3, dto 3, setc 3, setT 3, Pbus 17, Pstr 42, draw_bus 45, draw_shunt 91

 

Powered by Blogger | Designed by QooQ

keyboard_double_arrow_down

keyboard_double_arrow_down