ESP32: ILI9341 Display Hello world - JohnHau/mis GitHub Wiki

Introduction In this tutorial we are going to learn how to write text to a ILI9341 display using the ESP32 and the Arduino core.

Note that the ILI9341 is actually the LCD driver (you can check the datasheet here) but, for simplicity, we will refer to the display using this name. In my case, I’m using a 2.4″ TFT display, with 240×320 pixels, bought at eBay.

There are a lot of Arduino libraries available that allow us to interact with these displays without having to worry about the lower level details. For this tutorial we are going to use the Arduino_GFX.

As shown in figure 1, you can install the library from the Arduino IDE Library Manager.

image

image

image

image

image

image

image

Arduino_ESP32SPI bus = Arduino_ESP32SPI(TFT_DC, TFT_CS, TFT_SCK, TFT_MOSI, TFT_MISO);

image

image

image

#include <Arduino_GFX_Library.h>

#define TFT_SCK 18 #define TFT_MOSI 23 #define TFT_MISO 19 #define TFT_CS 22 #define TFT_DC 21 #define TFT_RESET 17

void setup(void) {

Arduino_ESP32SPI bus = Arduino_ESP32SPI(TFT_DC, TFT_CS, TFT_SCK, TFT_MOSI, TFT_MISO); Arduino_ILI9341 display = Arduino_ILI9341(&bus, TFT_RESET);

display.begin(); display.fillScreen(WHITE); display.setCursor(20, 20); display.setTextSize(2); display.setTextColor(BLUE); display.print("Hello world"); }

void loop() {}

Testing the code To test the previous code, simply compile it and upload it to your ESP32, after wiring it to the display accordingly to the diagram shown before in figure 2.

You should obtain a result similar to figure 3. As can be seen, we get the “Hello World” message we defined in our code.

image