ILI9341 TFT LCD to ESP32 - Full HOW TO for display, SD card and Touch. Using TFT_eSPI driver
Table of Contents
Introduction
This tutorial will guide you through the process of connecting and using an ILI9341 TFT LCD display with an ESP32. We will cover the setup for the display, SD card, and touch functionality using the TFT_eSPI library. By the end of this guide, you will have a fully operational display system that can be easily integrated into your projects.
Step 1: Gather Your Materials
Before starting, ensure you have the following components ready:
- ILI9341 TFT Display
- ESP32 Development Board
- 8GB SD Card
- Jumper wires
- Breadboard (optional)
Step 2: Connect the Hardware
Follow these steps to wire the ILI9341 TFT display and the SD card to the ESP32:
-
Connect the TFT Display:
- VCC to 3.3V on ESP32
- GND to Ground
- CS (Chip Select) to GPIO 15
- RESET to GPIO 4
- DC/RS (Data/Command) to GPIO 2
- SD_CS (SD Card Chip Select) to GPIO 5
- SCK (Clock) to GPIO 14
- MOSI (Master Out Slave In) to GPIO 23
- MISO (Master In Slave Out) to GPIO 19
-
Connect the SD Card:
- Ensure the SD card module is connected to the SD_CS pin defined above (GPIO 5) and the SPI pins (SCK, MOSI, MISO) as mentioned.
-
Connect the Touch Screen:
- For touch functionality, connect:
- T_CS (Touch Chip Select) to GPIO 21 (uncomment this line in User_Setup.h)
- For touch functionality, connect:
Step 3: Install the TFT_eSPI Library
- Open the Arduino IDE.
- Go to Sketch > Include Library > Manage Libraries.
- Search for "TFT_eSPI" and install the latest version.
Step 4: Configure User_Setup.h
- Navigate to the TFT_eSPI library folder in your Arduino libraries.
- Open the User_Setup.h file.
- Uncomment the following line to enable touch functionality:
#define TOUCH_CS 21 // Chip select pin (T_CS) of touch screen
- Adjust other settings in the file as needed, such as the SPI bus pins to match your wiring.
Step 5: Upload Example Code
- In the Arduino IDE, go to File > Examples > TFT_eSPI > choose an example sketch (e.g.,
TFT_eSPI_Example
). - Ensure that the selected board is the ESP32 by going to Tools > Board > select your ESP32 model.
- Upload the example sketch to your ESP32.
Step 6: Test the Setup
- Once uploaded, open the Serial Monitor in the Arduino IDE.
- Set the baud rate to match your sketch (usually 115200).
- You should see the display initializing and showing graphics from the example.
Conclusion
You've successfully set up an ILI9341 TFT display with an ESP32, including SD card and touch functionalities. Ensure to check the wiring, library configurations, and uncomment the necessary lines in User_Setup.h for touch support. Now you can explore additional examples or start building your own applications using this setup!