Interfacing ESP8266 NodeMCU with ILI9341 TFT display

This tutorial shows how to interface ESP8266 NodeMCU (ESP-12E) board with ILI9341 TFT display.
The ILI9341 TFT module contains a display controller with the same name: ILI9341. It’s a color display that uses SPI interface protocol and requires 4 or 5 control pins, it’s low cost and easy to use.
The resolution of this TFT display is 240 x 320 which means it has 76800 pixels. This module works with 3.3V only and it doesn’t support 5V (not 5V tolerant).

TFT: Thin-Film Transistor.
SPI: Serial Peripheral Interface.

Project Hardware Required:

  • NodeMCU board
  • ILI9341 TFT display module (2.2″, 2.4″, 2.8″ …)
  • Micro USB cable (for programming and powering the whole circuit)
  • Breadboard
  • Jumper wires

ESP8266 NodeMCU with ILI9341 SPI color TFT

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

The ILI9341 TFT display board which is shown in project circuit diagram has 14 pins, the first 9 pins are for the display and the other 5 pins are for the touch module.

So, the display part pins are numbered from 1 to 9 (from left to right): VCC (5V), GND (ground), CS (chip select), RST (reset), DC (or D/C: data/command), MOSI (or SDI), SCK (clock), BL (back light LED) and MISO (or SDO).
MOSI: master-out slave-in.
SDI: serial data in.
MISO: master-in slave-out.
SDO: serial data out.

ESP8266 NodeMCU ILI9341 TFT display

The ILI9341 TFT display is connected to the NodeMCU board as follows:
CS pin is connected to D2 (ESP8266EX GPIO4),
RST pin is connected to D3 (ESP8266EX GPIO0),
D/C pin is connected to D4 (ESP8266EX GPIO2),
MOSI pin is connected to D7 (ESP8266EX GPIO13),
SCK pin is connected to D5 (ESP8266EX GPIO14),
VCC and BL are connected to pin 3V3,
GND is connected to pin GND of the NodeMCU board.

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).

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

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

The previous two libraries can also be installed manually:
Download both libraries from the following two links:
Adafruit ILI9341 TFT library   —->  direct link
Adafruit graphics library        —->  direct link

Go to Arduino IDE —> Sketch —> Include Library —> Add .ZIP Library … and browse for the .zip file (previously downloaded).
The same thing for the second file.

Hints:
The previous 2 libraries are included in the main code as shown below:

The ILI9341 TFT display is connected to NodeMCU hardware SPI module pins (clock and data), the other pins which are: CS (chip select), RST (reset) and DC (data/command) are defined as shown below:

Full Arduino code:
The following Arduino code is from Adafruit ILI9341 library (graphicstest.ino) with some modifications in order to work with the above circuit diagram.

The following video shows my simple hardware circuit test:

15 thoughts on “Interfacing ESP8266 NodeMCU with ILI9341 TFT display”

  1. I’m getting a white screen. I’m using an Arduino Nano. Any ideas how to fix this? I have tried changing the code to the suggestions above

  2. I have the 128×160 Version of a similar display. In general it works but the Text is broken e.g. it it is mirrored and writing from right to left. Any ideas how to fix that?
    Im am currently testing the code line by line and inspecting the output.
    thanks
    Erdie

    1. If in case, you still have the issue
      Like Pete mentioned,
      #define TFT_CS 4 // TFT CS pin is connected to NodeMCU pin D2 = GPIO 4
      #define TFT_RST 0 // TFT RST pin is connected to NodeMCU pin D3 = GPIO 0
      #define TFT_DC 2 // TFT DC pin is connected to NodeMCU pin D4 = GPIO 2

      this should do the job

    2. Have you tried this, it worked for me,
      #define TFT_MOSI D7
      #define TFT_SCLK D5
      #define TFT_CS D2 // Chip select control pin
      #define TFT_DC D4 // Data Command control pin
      #define TFT_RST D3 // Reset pin (could connect to RST pin)

  3. For some reason the pins on my ESP8266 12-E NodeMCU Kit weren’t defined as D2 D3 and D4 ; if you get an error on compile try replacing the define lines as such:

    #define TFT_CS 4 // TFT CS pin is connected to NodeMCU pin D2 = GPIO 4
    #define TFT_RST 0 // TFT RST pin is connected to NodeMCU pin D3 = GPIO 0
    #define TFT_DC 2 // TFT DC pin is connected to NodeMCU pin D4 = GPIO 2

    1. Thank you! This made it work for me. (Actually I’m using a different display and even a different display driver. I’m also using the LoLin NodeMCU module.) Regardless of all that, it’s working thanks to you.

    1. I changed setup to this and it worked
      #define TFT_MOSI D7
      #define TFT_SCLK D5
      #define TFT_CS D2 // Chip select control pin
      #define TFT_DC D4 // Data Command control pin
      #define TFT_RST D3 // Reset pin (could connect to RST pin)

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top