Using ESP32 with Arduino IDE to Control an LCD Display

In today’s embedded systems development, controlling an LCD display with ESP32 is a common but challenging task. This article will guide readers through using the Arduino development environment to control a Raspberry Pi LCD display with a 3.5-inch size and 480×320 resolution, driven by the ILI9486 chip.

Development Approaches for ESP32

ESP32 commonly supports three development approaches: ESP-IDF, MicroPython, and Arduino IDE.

ESP-IDF is the official development framework provided by Espressif Systems for its ESP32 and ESP32-S series chips. It comes with a complete toolchain and software libraries to help developers easily build robust IoT applications. Although ESP-IDF offers more efficient development, it is more challenging, making it less prevalent in open-source projects and more suitable for professionals in the embedded field.

MicroPython uses the Python language, which is advantageous for developers familiar with Python. MicroPython supports interactive development on devices, allowing developers to interact directly with the device via serial or network connections, speeding up design. However, MicroPython has fewer users, which may limit access to help and support in online communities.

Arduino IDE, developed by the Arduino team, simplifies Arduino development significantly with rich open-source libraries and C++ language, which is the focus of this article. While Arduino IDE is designed for Arduino development, it can also be used in some cases for other types of development boards and microcontrollers, as long as these devices are compatible with Arduino IDE and support the Arduino programming language.

Adding ESP32 to Arduino IDE

In Arduino IDE, navigate to “File” -> “Preferences” and enter the ESP32 board information URL in the “Additional Board Manager URLs” field. This URL points to the Arduino board support library for ESP32, allowing Arduino IDE to download the necessary board support.

Next, in Arduino IDE, navigate to “Tools” -> “Board” -> “Board Manager” and search for “esp32”. Find the corresponding ESP32 board support library and click “Install”. After installation, Arduino IDE will automatically download and install the toolchain, library files, etc., required for ESP32 development.

Once installation is complete, navigate again to “Tools” -> “Board”, where you will see a range of ESP32 development board options. Here, you can select the ESP32 development board model that suits your needs, such as “ESP32 Wrover Module” or “ESP32 Dev Module”. After selecting the appropriate board model, Arduino IDE will configure the corresponding compilation options for you.

Installing Required Libraries

Based on your project requirements, open Arduino IDE, navigate to “Tools” -> “Manage Libraries…”, and search for the names of the required libraries. Install them, and once installation is complete, you can reference these libraries in your project and use the functionality they provide.

Adafruit_BusIO: A library for managing and controlling various bus devices, providing a universal bus interface for many Adafruit sensors and devices, simplifying code writing and device management.

Adafruit_ILI9341: The ILI9341 controller is a common SPI interface color TFT LCD controller. This library makes it easier to use LCD displays with this controller.

Adafruit-GFX: A library for drawing graphics, providing a range of functions for drawing various graphic elements (such as lines, circles, rectangles, etc.), compatible with various display libraries.

TFT_eSPI: A universal LCD display library for ESP8266 and ESP32 developed based on Adafruit_GFX. It not only supports multiple display controllers but also facilitates compatibility with various Adafruit display libraries.

Wiring

The pin definitions of the ESP32 development board and the Raspberry Pi LCD display are as follows:

Pin definition of esp32 board

The pin definitions of the Raspberry Pi LCD display used are as follows:

Raspberry Pi LCD pin definition

Pin NumberLabelDescription
1, 173.3VPositive Power Supply (3.3V Power Input)
2, 45VPositive Power Supply (5V Power Input)
3, 5, 7, 8, 10, 12, 13, 15, 16NCNot Connected
6, 9, 14, 20, 25GNDGround (Power Ground)
11TP IRQTouch Panel Interrupt, low level when touch detected
18LCD RSInstruction/Data Register Select, low for instruction, high for data
19LCD SI/TP SISPI Data Input for LCD/Touch Panel
21TP SOSPI Data Output for Touch Panel
22RSTReset
23LCD SCK/TP SCKSPI Clock Signal for LCD/Touch Panel
24LCD_CSLCD Chip Select, low to select LCD
26TP CSTouch Panel Chip Select, low to select touch panel

The wiring between ESP32 and LCD is as follows:

RPi 3.5” TFT&TouchESP32
5V5V
GNDGND
LCD_RS (pin 18)gpio15
LCD_SI/TP_Sl (pin 19)gpio12
TP SO (pin 21)gpio2
RST (pin 22)gpio13
LCD_SCK/TP_ SCK (pin 23)gpio14
LCD_CS (pin 24)gpio5
TFT_CS (pin 26)gpio18

Modifying the Driver

The TFT_eSPI driver library is a universal LCD screen driver library. To adapt this library to your specific hardware, manual configuration is required.

First, locate the TFT_eSPI file and modify the User_Setup_Select.h file, which is used to select and configure the correct hardware setup file so that the TFT_eSPI library can work correctly with your hardware.

  • Comment out the line #include <User_Setup.h> to avoid redundancy and confusion since a comprehensive configuration is provided later, eliminating the need to manually include the setup file.
  • Uncomment the line #include <User_Setups/Setup11_RPi_touch_ILI9486.h> as this setup file is prepared for ESP32 and Raspberry Pi TFT with touch, which suits our configuration.

In the User_Setup_Select.h file’s parent directory, locate the User_Setups folder, open it, and modify the Setup11_RPi_touch_ILI9486.h file.

  • Comment out the initial lines as our wiring differs from the file:
				
					#define TFT_MISO 19
#define TFT_MOSI 23
#define TFT_SCLK 18
#define TFT_CS   15  // Chip select control pin
#define TFT_DC    2  // Data Command control pin
#define TFT_RST   4  // Reset pin (could connect to RST pin)
#define TOUCH_CS 22     // Chip select pin (T_CS) of touch screen
				
			
  • Then redefine them as follows:
				
					#define TOUCH_CS 18
#define TFT_MISO 2
#define TFT_MOSI 12
#define TFT_SCLK 14
#define TFT_CS   5
#define TFT_DC   15
#define TFT_RST  13
				
			

Running Demo Test

First, open Arduino IDE, then click “File” -> “Examples” -> “TFT_eSPI” -> “480×320” -> “TFT_Rainbow480”. This step opens the “TFT_Rainbow480” example program in the TFT_eSPI library.

Different development boards and ports require different configurations and parameters. After opening the example program, set them to ensure correct compilation and upload to the target device.

Once the development board and port settings are complete, click the upload button in the Arduino IDE to compile and upload the example program to the target device (development board). After uploading the program, Arduino IDE will send the compiled binary file to the development board and start executing the example program.

final renderings

You Might Be Interested

what is esp32
What is an ESP32

Dive into the world of microcontrollers with TechSparks’ comprehensive guide to the ESP32! Discover the power of this versatile chip, renowned for its integration, low

esp32 ledc
ESP32 LEDC: Precise Control for Diverse Applications

Dive into the world of precise LED control with ESP32’s LEDC module, revolutionizing microcontroller-based PWM technology for versatile applications. Explore the enhanced capabilities, flexible programming

esp32 connect to wifi
Connecting ESP32 to WiFi in 4 Steps

Unlock the potential of your ESP32 with these 4 simple steps to WiFi connectivity! Dive into the world of IoT and remote control effortlessly, as

Getting Started with ESP-IDF in VSCode
Getting Started with ESP-IDF in VSCode

This guide introduces an efficient method, “ESP-IDF + VSCode,” for ESP32 development, simplifying environment setup and allowing seamless switching between ESP-IDF versions. It covers downloading

How to Enable Multi-Core on ESP32 Microcontroller
How to Enable Multi-Core on ESP32 Microcontroller

This comprehensive guide elucidates the process of enabling multi-core functionality on the ESP32 microcontroller, leveraging its dual-core architecture for enhanced parallel processing capabilities. Through detailed

Scroll to Top