Skip to Content

Interface GMT020-02 Display with ESP32

Interface GMT020-02 Display with ESP32

In this tutorial you will learn how to interface and control the GMT020-02 TFT Display with an ESP32. The GMT020-02 Display uses the ST7789 driver IC, so this tutorial should be useful for other TFT displays with the same driver IC as well.

The GMT020-02 is an nice little 2.0″ TFT display with a resolution of 240×320 pixels and 262K colors that you can get for cheap at AliExpress. However, the documentation is sparse and sometimes even misleading, which makes it unnecessarily hard to use the display. I hope this little tutorial helps.

Features of the GMT020-02 Display

The GMT020-02 Vers 1.1 is a display module with an integrated SPI interface. The picture below show the front and back of the module.

Front and Back of GMT020-02 Vers 1.1 Display
Front and Back of GMT020-02 Vers 1.1 Display

You can find it on AliExpress, where it is labelled as using an ST7735 driver IC and being suitable for Arduino.

GMT020-02 on AliExpress

Driver IC for GMT020-02 Display

This is misleading since the datasheet states that the driver IC is an ST7789 and that the module runs on 3.3V. According to the schematics there is no level converter on the module, which makes it risky to connect it to an Arduino UNO with 5V logic. The datasheets for the GMT020-02 module and the ST7789 are linked below.

Backlight for GMT020-02 Display

Also a word on the backlight. The GMT020-02 module has a backlight but unfortunately it seems to be hardwired (see LED+ and LED- in the schematics below) and therefore cannot be controlled via software. You will notice there is also no BLK or LED pin, which would allow you to control the backlight externally.

Schematics for Backlight LED
Schematics for Backlight LED (source)

The only way would be to switch of the power to the module completely. But since the backlight LED already draws 60mA you cannot provide VCC directly from a GPIO output! You will have to use a transistor/MOSFET to switch the power supply (VCC)!

Communication interface of GMT020-02 Display

By the way, the IM0, IM1 and IM2 pins in the schematics above are for selecting the communication interface (SPI or 8bit parallel). From the table below and the schematics you can see that the module is hardwired to use SPI:

Interface table for GMT020-02
Interface table for GMT020-02 (source)

Connecting GMT020-02 Display with ESP32

Connecting the GMT020-02 to an ESP32 is easy but the labelling of the pins on the GMT020-02 is a bit confusing. It shows SDA and SCL pins but since it uses an SPI interface, these are not the SDA and SCL pins for I2C!

The following wiring diagram shows you how to connect the GMT020-02 to an WEMOS Lolin32 lite:

Connecting GMT020-02 with WEMOS Lolin ESP32 lite

And here for your convenience the required connections as a table:

DisplayESP32
CS / SS5
RST17
DC16
SDA / MOSI23
SCL / SCLK18
GNDGND
VCC3.3V

Depending on the ESP32 and development board you are using, these pins will differ. You should use the pins for hardware SPI. You can find them by selecting your board in the Arduino IDE and then running the code below.

void setup() {
  Serial.begin(115200);
  Serial.print("MOSI: ");
  Serial.println(SDA / MOSI);
  Serial.print("MISO: ");
  Serial.println(MISO);
  Serial.print("SCL / SCK: ");
  Serial.println(SCK);
  Serial.print("CS / SS: ");
  Serial.println(SS);  
}

void loop() { }

It prints out the pins you need for hardware SPI. The remaining pins you can select freely.

Test Code for GMT020-02 Display

We are going to use the Adafruit-ST7735 Library to write and draw onto the GMT020-02 display. To install it just open the Library Manager, search for “Adafruit-ST7735” and click on the green INSTALL button:

Adafruit-ST7735 in Library Manager
Adafruit-ST7735 in Library Manager

The installer will probably prompt you to install the dependencies as well. Click on INSTALL ALL:

Install the dependencies for Adafruit-ST7735 Library
Install Dependencies for Adafruit-ST7735 Library

With the library installed, we can now test the display. Just compile and upload the following code. It prints the text “Makerguides” on the display:

#include <Adafruit_GFX.h>      
#include <Adafruit_ST7789.h>   

// WEMOS LOLIN32 lite
#define TFT_CS    5 
#define TFT_RST   17
#define TFT_DC    16
#define TFT_MOSI  23   // SDA, HW MOSI
#define TFT_SCLK  18   // SCL, HW SCLK
// #define TFT_MISO 19  // not used

//Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST); // Hardware SPI

void setup() {
  tft.init(240, 320);
  tft.setRotation(1);          
  tft.fillScreen(ST77XX_BLACK);

  tft.setTextColor(ST77XX_WHITE);
  tft.setTextSize(3);
  tft.setCursor(50, 100);
  tft.println("Makerguides");
}

void loop() {
}

If you connected the display to the correct hardware SPI of your ESP32 pins you actually don’t need to define TFT_MOSI and TFT_SCLK and can use the following constructor (as in the code above):

Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);

Hardware SPI is faster but if you are having issues, you can try software SPI by defining your TFT_MOSI and TFT_SCLK pins and using them in the constructor.

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

In any case, the output on the display should look like follows:

Output on GMT020-02 display
Output on GMT020-02 display

If that works, you can then run the graphicstest_st7789 code that comes with the Adafruit-ST7735 Library. Just make sure you select the correct display in the code and change the pins to your wiring:

// OPTION 1 (recommended) is to use the HARDWARE SPI pins, which are unique
// to each board and not reassignable. 

Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);

// OPTION 2 lets you interface the display using ANY TWO or THREE PINS,
// tradeoff being that performance is not as fast as hardware SPI above.

//Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
void setup(void) {
  Serial.begin(9600);
  Serial.print(F("Hello! ST77xx TFT Test"));

  // Use this initializer (uncomment) if using a 1.3" or 1.54" 240x240 TFT:
  // tft.init(240, 240);           // Init ST7789 240x240

  // OR use this initializer (uncomment) if using a 1.69" 280x240 TFT:
  //tft.init(240, 280);           // Init ST7789 280x240

  // OR use this initializer (uncomment) if using a 2.0" 320x240 TFT:
  tft.init(240, 320);           // Init ST7789 320x240

  // OR use this initializer (uncomment) if using a 1.14" 240x135 TFT:
  //tft.init(135, 240);           // Init ST7789 240x135
  
  // OR use this initializer (uncomment) if using a 1.47" 172x320 TFT:
  //tft.init(172, 320);           // Init ST7789 172x320

  // OR use this initializer (uncomment) if using a 1.9" 170x320 TFT:
  //tft.init(170, 320);           // Init ST7789 170x320

GMT020-02 Display with TFT_eSPI library

If you want to use the TFT_eSPI library instead of the Adafruit-ST7735 Library that is possible as well. Here is the tft_setup.h file with the required configuration (again for an WEMOS Lolin32 lite):

#define ST7789_DRIVER
   
#define TFT_WIDTH  240
#define TFT_HEIGHT 320
#define TFT_RGB_ORDER TFT_BGR

// WEMOS Lolin32 lite
#define TFT_CS    5   
#define TFT_RST   17  
#define TFT_DC    16  
#define TFT_MOSI  23  // SDA // HW MOSI
#define TFT_SCLK  18  // SCL // HW SCLK
// #define TFT_MISO 19  // not used

#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  40000000
#define SPI_READ_FREQUENCY  20000000

and here is a code example that as before prints the text “Makerguides” on the display:

#include "tft_setup.h"
#include"TFT_eSPI.h"

TFT_eSPI tft = TFT_eSPI();

void setup(void) {
  tft.init();
  tft.fillScreen(TFT_BLACK);  
  tft.setRotation(1);

  tft.setCursor(100, 100, 2);  
  tft.setTextColor(TFT_WHITE, TFT_BLACK);
  tft.setTextSize(2);
  tft.println("Makerguides");
}

void loop() { }

Remember that the tft_setup.h file must be part of the project folder. If you need more details have a look at the How to configure TFT_eSPI Library for TFT display tutorial.

Conclusion

In this tutorial you learned how to interface and control the GMT020-02 TFT Display with an ESP32.

For other TFT displays have a look at the Interface TFT ILI9341 Touch Display with ESP32, the
Interface TFT ST7735 Display with ESP32, the Digital Clock on CrowPanel 1.28″ Round Display, and the CrowPanel 2.8″ ESP32 Display : Easy Setup Guide tutorials.

If you have any comments, feel free to leave them in the comment section.

Happy Tinkering ; )