/ESP32_LCD

ESP32 project to display a GUI on ILI9341 320x240 LCD with touch controller XPT2046

MIT LicenseMIT

ESP32_LCD

ESP32 project to display a GUI on ILI9341 320x240 LCD with touch controls. GUI consist of the clock and stopwatch.

To set up the ESP-IDF, go through this link

Used packages

In order to use LVGL and LVGL driver to display GUI with widgets, specific version of them( git commit hash) must be used.

LCD controller ILI9341 with touch controller XPT2046 pin connections

LCD ILI9341 comes with the touch controller XPT2046. LCD and touch controller both are connected to ESP32 on SPI bus. As shown in the image of the back side of LCD, there are different set of pins for both of them and they needs to be connected to the GPIO pins of ESP32.

drawing

After connecting LCD pins to GPIO, these configuration must be done in the project. For this esp-idf provides menuconfig. idf.py menuconfig command opens the menuconfig.

LCD Pin Assignments to ESP32 GPIO number

Select Component Config->LVGL TFT Display controller->Display Pin Assignments and enter the following values

Pin Name Menuconfig GPIO PIN number
SDI(MOSI) GPIO for MOSI 14
SDO(MISO) GPIO for MISO 34
SCK(CLK) GPIO for CLK(SCK/Serial Clock) 23
CS GPIO for CS (Slave select) 27
DC GPIO for DC (Data/Command) 22
GND - ESP32 GND Pin
VCC - ESP32 3v3 Pin
LED - ESP32 3v3 Pin
Reset GPIO for Reset 12
  • Select Component Config->LVGL TFT Display controller->Select a display controller model and select ILI9341 from the options
  • Select Component Config->LVGL TFT Display controller->Display orientation and select Landscape from the options. Here Portrait can also be selected
  • Select Component Config->LVGL TFT Display controller->TFT SPI Bus and select HSPI from the options

Touch controller XPT2046 Pin assignaments to ESP32 GPIO number

Since both LCD controller and touch controller are connected on SPI bus, the values of MISO, MOSI, and CLK is same, only CS (Slave Select) is connected to different GPIO pin. To configure touch controller, go to menuconfig and select Component Config->LVGL Touch controller->Touchpanel (XPT2056) Pin Assignments

Pin Name Menuconfig GPIO Pin Number
T_DO (MISO) GPIO for MISO 34
T_DIN (MOSI) GPIO for MOSI 14
T_CS GPIO for CS 32
T_CLK GPIO for CLK 23

LVGL touch drivers also needs to know about the values/data provided by XPT2046 pin when the surface of LCD is touched at min/max X coordinate (lower left and upper right corner) and min/max Y coordinate (lower right ad upper left corner). For this go to Component Config->LVGL Touch controller->Touchpanel Configuration

Menuconfig values
Minimum X coordinate value 183
Minimum Y coordinate value 134
Maximum X coordinate value 1959
Maximum Y coordinate value 1843

X/Y values require inversion for landscape mode (y means marked in menuconfig GUI)

Menuconfig Variable Name values
Invert X coordinate value y
Invert X coordinate value y
  • LCD resolution 320x240 can be configured in Component Config->LVGL configuration

  • To configure XPT2046 as a touch controller, select Component Config->LVGL Touch controller->Select Touchpanel controller model and select XPT2056 from options.

Clock Tab Image

drawing

Stopwatch Tab Image

drawing

Useful esp-idf commands

  • To flash the project executable:

    Navigate to folder where repo is cloned

  • In order to flash, take the ownership of the USB port where ESP32 is connected

      sudo chown <USER> <PORT>
    

    e.g. USER = Monty, PORT = /dev/ttyUSB0

  • To flash the project executable and start monitoring

      idf.py -p <PORT> flash monitor
    
  • To only monitor the process via serial port

      idf.py monitor
    

References

  1. FreeeRTOS Reference books
  2. ESP-IDF API guide
  3. LVGL Widgets documentation
  4. LVGL with ESP-IDF project
  5. Sample ESP-IDF project with LVGL
  6. Example ESP32 project with LCD