Interfacing ESP8266 NodeMCU with ST7789 TFT Display

This tutorial shows how to interface ESP8266 NodeMCU (ESP-12E) board with ST7789 TFT display.
The ST7789 TFT module contains a display controller with the same name: ST7789. It’s a color display that uses SPI interface protocol and requires 3, 4 or 5 control pins, it’s low cost and easy to use.
This display is an IPS display, it comes in different sizes (1.3″, 1.54″ …) but all of them should have the same resolution of 240×240 pixel, this means it has 57600 pixels. This module works with 3.3V only and it doesn’t support 5V.

TFT: Thin-Film Transistor.
SPI: Serial Peripheral Interface.
IPS: In-Plane Switching.

The following image shows a ST7789 display module provided by Adafruit Industries:

Adafruit ST7789 TFT display module
Adafruit ST7789 TFT display module

Another version of the ST7789 display module is shown below. This one has no CS (chip select) pin, its internally attached to GND:

ST7789 TFT display without CS pin
ST7789 TFT display without CS pin

Project Hardware Required:

  • NodeMCU board
  • ST7789 TFT display module (1.3″, 1.54″ …)
  • Micro USB cable (for programming and powering the whole circuit)
  • Breadboard
  • Jumper wires
NodeMCU WiFi board with ST7789 TFT display

NodeMCU with ST7789 TFT display circuit:
Project circuit schematic diagram is shown below.

The ST7789 display module shown in project circuit diagram has 7 pins: (from right to left): GND (ground), VCC, SCL (serial clock), SDA (serial data), RES (reset), DC (or D/C: data/command) and BLK (back light).
Connecting the BLK pin is optional. The back light turns off when the BLK pin connected to the ground (GND).

ESP8266 NodeMCU ST7789 SPI TFT circuit

The ST7789 TFT display module is connected to the NodeMCU board as follows:
GND is connected to pin GND of the NodeMCU board,
VCC and BL are connected to pin 3V3,
SCL pin is connected to D5 (ESP8266EX GPIO14),
SDA pin is connected to D7 (ESP8266EX GPIO13),
RES pin is connected to D2 (ESP8266EX GPIO4),
DC pin is connected to D1 (ESP8266EX GPIO5).

If the display module has a CS pin (Chip Select) then it should be connected to NodeMCU pin D8 (GPIO15).

Pins D5 (GPIO14) and D7 (GPIO13) are hardware SPI module pins of the ESP8266EX microcontroller respectively for SCK (serial clock) and MOSI (master-out slave-in).

NodeMCU with ST7789 TFT display code:
The Arduino code below requires two libraries from Adafruit Industries:
The first library is a driver for the ST7789 TFT display which can be installed from Arduino IDE library manager (Sketch —> Include Library —> Manage Libraries …, in the search box write “st7789” and install the one from Adafruit).

The second library is Adafruit graphics library which can be installed also from Arduino IDE library manager.

Both libraries can be installed manually, first download them from the following 2 links:
Adafruit ST7789 TFT library    —->  direct link
Adafruit graphics library        —->  direct link

After the download, go to Arduino IDE —> Sketch —> Include Library —> Add .ZIP Library … and browse for the .zip file (previously downloaded).
The same thing for the other library file.

Hints:
The 2 library files are included in the main code as shown below.

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789

The ST7789 TFT module pins (CS, RST and DC) connections are defined as shown below:

// ST7789 TFT module connections
#define TFT_DC    D1     // TFT DC  pin is connected to NodeMCU pin D1 (GPIO5)
#define TFT_RST   D2     // TFT RST pin is connected to NodeMCU pin D2 (GPIO4)
#define TFT_CS    D8     // TFT CS  pin is connected to NodeMCU pin D8 (GPIO15)

The other display pins (SDA and SCL) are connected to NodeMCU hardware SPI pins (respectively D7 and D5).

The Adafruit ST7789 library is initialized with this line:

// Initialize Adafruit ST7789 TFT library
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);

And the TFT display is initialized using the following command:

// if the display has CS pin try with SPI_MODE0
tft.init(240, 240, SPI_MODE2);    // Init ST7789 display 240×240 pixel

The display may not work if it has a CS pin, try with SPI_MODE0 which is the default mode of the library or just use: tft.init(240, 240);

Rest of code is described through comments.

Full Arduino code:

TFT Display Interfacing

Deja un comentario