ILI9341 TFT LCD to ESP32 - Full HOW TO for display, SD card and Touch. Using TFT_eSPI driver

3 min read 2 months ago
Published on Aug 24, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

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:

  1. 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
  2. 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.
  3. Connect the Touch Screen:

    • For touch functionality, connect:
      • T_CS (Touch Chip Select) to GPIO 21 (uncomment this line in User_Setup.h)

Step 3: Install the TFT_eSPI Library

  1. Open the Arduino IDE.
  2. Go to Sketch > Include Library > Manage Libraries.
  3. Search for "TFT_eSPI" and install the latest version.

Step 4: Configure User_Setup.h

  1. Navigate to the TFT_eSPI library folder in your Arduino libraries.
  2. Open the User_Setup.h file.
  3. Uncomment the following line to enable touch functionality:
    #define TOUCH_CS 21 // Chip select pin (T_CS) of touch screen
    
  4. Adjust other settings in the file as needed, such as the SPI bus pins to match your wiring.

Step 5: Upload Example Code

  1. In the Arduino IDE, go to File > Examples > TFT_eSPI > choose an example sketch (e.g., TFT_eSPI_Example).
  2. Ensure that the selected board is the ESP32 by going to Tools > Board > select your ESP32 model.
  3. Upload the example sketch to your ESP32.

Step 6: Test the Setup

  1. Once uploaded, open the Serial Monitor in the Arduino IDE.
  2. Set the baud rate to match your sketch (usually 115200).
  3. 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!