I'm currently using a 80x160 pixel TFT display as interface for my project.
I'm using the Adafruit_ST7735 + Adafruit_GFX libraries with hardware SPI to use the display, and they are doing a great job.
However, I recognized that the initialization of the display seems to be quite slow (1163 ms per init), but I can't find anything online that somebody else is facing the same issue. I get this behavior on different platforms with just some ms difference (Arduino, Wemos etc.). This is basically my cleared code:
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
void setup(void) {
tft.initR(INITR_MINI160x80); // init display size = 1163 ms
tft.initR(ST7735_MADCTL_BGR); // init display colors (its BGR and not RGB) = 1163 ms
}
The problem is: The microcontroller will only be powered while I'm pressing a button in my project. I would love to reduce the waiting time, if there is a way. Am I using the lib wrong?
Thanks in advance and sorry if there are any formatting issues, it's my first post
In the code that you share with us, the screen doesn't really execute anything, could you please share the complete example to reproduce the behavior and by the way, how do you measure those 1163 ms?
Hi Edison,
actually the initialization needs that time anyway, no matter what I show after the setup in my loop. The execution of everything else is fast, just this initialization is slow.
But I copied the main setup with which I tested the times (pinout for wemos D1 mini), you can plot what ever you want in the loop.
I use the tft to display a battery voltage and a smd thermometer (TMP1075NDRLR) which is controller by SPI as well. Could this be an issue?
Best regards,
Dominik
// external libraries
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
#include <SPI.h>
#include <Wire.h>
#include <Arduino.h>
#include <Temperature_LM75_Derived.h>
// --------------------------------------- Pinout ---------------------------------------
// analog part
#define PIN_BAT A0 // battery voltage input
#define PIN_DMS D6 // dead man switch
// temperature sensor over I²C
#define TFT_SCL D1 // SCL for I²C
#define TFT_SDA D2 // SDA of I²C
// display: Uses hardware SPI since it is much faster than I2C
#define TFT_BLK D0 // 3,3 pwm for backlight control
#define TFT_RST D3 // to "RES" in display
#define TFT_DC D4 // to "DC" in display
#define TFT_SCLK D5 // to "SCL" in display
#define TFT_MOSI D7 // to "SDA" in display
#define TFT_CS D8 // to "CS" in display
// --------------------------------------- Parameters ---------------------------------------
// display object
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
// temperature object
Generic_LM75 temperature;
//timer
volatile long boot_time = 0;
void setup(void) {
// measure start time
boot_time = millis();
Serial.begin(115200);
Wire.begin();
Serial.println("\n\n----- Setup Start -----");
long t1 = millis();
Serial.println(" -> Time wire: " + String(t1-boot_time) + " ms");
// define pin modes
pinMode(PIN_BAT, INPUT);
pinMode(TFT_BLK, OUTPUT);
digitalWrite(TFT_BLK, LOW);
long t2 = millis();
Serial.println(" -> Time config: " + String(t2-t1) + " ms");
//Initialize display
tft.initR(INITR_MINI160x80); // Init ST7735S mini display
long t3 = millis();
Serial.println(" -> Time init 160x80: " + String(t3-t2) + " ms");
tft.initR(ST7735_MADCTL_BGR); // set right color panel
tft.setRotation(3); // set right panel angle
tft.setTextWrap(false); // no text wrap
long t4 = millis();
Serial.println(" -> Time display: " + String(t4-t3) + " ms");
tft.fillScreen(ST77XX_BLACK);
pinMode(PIN_DMS, OUTPUT);
digitalWrite(PIN_DMS, HIGH);
digitalWrite(TFT_BLK, HIGH);
long t5 = millis();
Serial.println(" -> Time plot: " + String(t5-t4) + " ms");
Serial.println("Total boot time: " + String(millis()-boot_time) + " ms");
Serial.println("\n\n----- Setup Finished -----\n");
delay(1000); // show image for x amount of time
start_time = millis(); // time for dead man
}
void loop() {
// print anything
tft.setTextSize(2);
tft.setTextColor(ST77XX_GREEN, ST77XX_BLACK);
tft.setCursor(10, 25);
tft.print("Hello Arduino Forum");
delay(2000);
}
I did not find the screen with a resolution like the one you have, I found one of 160x128 px. At the moment I have a teensy 4.1 board, I tried to check your example, but it doesn't compile because of the library:Temperature_LM75_Derived
Do you have a link to the exact library to be able to install it and verify your example?
But I just checked in my setup: the init-time is the same even without the temperature part. So you can just delete the temperature part and should measure significant initialization times. They might be faster than with wemos, but I assume still a couple of hundred ms.
That delay is caused by several functions that load the specific registers of the chipdriver and each one has a specific timeout, they are inside the .ccp file.
We must not lose sight of the fact that this library and other similar ones work for various TFT measurements. In the process of activating the SPI bus and loading all the necessary registers to activate the ST7735 chip, a certain time must be waited to avoid any error. This ST7735 controller is quite long-lived.
I do not recommend reducing the time by modifying the waiting times for the registers to be loaded, because errors could be produced during the operation of the TFT
Thanks for your feedback!
So there's no real work around for a faster boot, at least with this library. I can test if the init is faster in other tft libraries, maybe I will find something interesting.