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)
- Jumper wires
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.
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.
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.
The previous 2 libraries are included in the main code as shown below:
|#include <Adafruit_GFX.h> // include Adafruit graphics library|
#include <Adafruit_ILI9341.h> // include Adafruit ILI9341 TFT library
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:C
|#define TFT_CS D2 // TFT CS pin is connected to NodeMCU pin D2|
#define TFT_RST D3 // TFT RST pin is connected to NodeMCU pin D3
#define TFT_DC D4 // TFT DC pin is connected to NodeMCU pin D4
// initialize ILI9341 TFT library with hardware SPI module
// SCK (CLK) —> NodeMCU pin D5 (GPIO14)
// MOSI(DIN) —> NodeMCU pin D7 (GPIO13)
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
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.