Using touch on 2.8 inch ILI9341 LCD with ESP32

Hello experts,

A little stuck with my project where I'm using 2.8 inch LCD with inbuilt touch based on the ILI9341 chipset. All this on the ESP32.

I have been searching and I find libraries for the display part of the module, but everybody says that the touch is not supported for ESP32.

I want to check with the community if someone has been able to use the display and touch both together with the ESP32? Looking at the specs of the board, I'd assume that SPI part should be common for the display and touch (i.e. common CLK, MISO, MOSI) with separate chip select pins. In addition, we use the IRQ from the touch to detect whenever the screen is touched.

Might be my assumptions are too simplistic and there are other limitations to using it?

Thanks in advance!

Regards, Deepak

Yes, touch works with 2.8 TFT , Touch display with ESP32, I have used TFT_ESPI, select proper wiring from the user setup file in that library. TFT IRQ no need to use

Thankyou a ton for the info and confirmation! Will go ahead and use it.

Regards, Deepak

One more quick question if someone could help here.

From the product document shared I see that they seem to have used two different SPI buses. I see pin allocations for LCD SPI and Touch SPI are different even for CLK, MISO, MOSI.

But when I saw the TFT_eSPI library, I see that they're using common pins for CLK, MOSI, MISO and different pins for SS and D/C.

So my question is: whether the LCD is using different SPI buses internally for LCD and Touch? I would think that both LCD and Touch could be used independently and hence breakouts are different for SPI bus on that board, but on the uC side, they could share the same SPI bus.

Would that be a fair/correct understanding?

Regards, Deepak

One more issue I see here is as follows:

I have one peripheral connected to my ESP32 on SPI bus at a frequency of approx 800 Khz. Max I could increase it to some 2.4 MHz or so.

Looking into the library files, the SPI frequency of the TFT_eSPI driver seems to be lot higher (understandably so for display use).

Is this understanding correct? Would that mean that I'll have to run two SPI buses now? One for my slow peripheral and other for the LCD?

Some information on this would be greatly appreciated. My PCB design is stuck because of this :(

Regards, Deepak

No. You use Transactions e.g. SPI.beginTransaction(deepak_setting) when you access your slow peripheral.


Ohh wow! That is quite a handy option to have! I almost changed my schematic to use the HSPI bus on ESP32. What a save, thanks a ton for this. I'll try it out before finalising it.

Regards, Deepak


Followup on my query.

I have two ESP32 boards:

  1. ESP32 DevKit with 30 pins
  2. NodeMCU-32S board with 36 pins

We broke our heads for weeks and couldn't get the LCD working with board #2. We connected Vcc to 3.3V pin. When we tried to troubleshoot, we saw that as soon as we connected the LCD module to the board, the vtgs on Vin and 3V3 pin almost disappeared. We couldn't get any further with the troubleshooting so we just tried the board #1. And Voila! Immediately the LCD lit up.

Now we couldn't figure out why board #2 was not working and didn't want to spend any further time on it so we continued with board #1.

So LCD is now working, but unfortunately we can't get the touch to work.

Here's what we did:

  1. Connected SCK <-> T_CLK <-> ESP32_PIN18
  2. Connected SDI(MOSI) <-> T_DIN <-> ESP32_PIN23
  3. Connected SDO(MISO) <-> T_OUT <-> ESP32_PIN19
  4. Connected T_CS <-> ESP32_PIN21

This, along with the existing connections for the LCD part.

As soon as we powered up the board and the LCD, things went blank on the LCD. Just the backlit.

I'm suspecting we're doing something wrong with the connections. Would someone be so kind to help us out here? Might be if we can have the ckt if someone has already made this work? Would be of immense help.

Regards, Deepak

Seriously. You have an ESP32. Use Bodmer's TFT_eSPI library.

If you have a problem: 1. Paste your "User_Setup.h" 2. Post a schematic or photo of your actual wiring. 3. Quote which library example you are using. 4. Explain your problem i.e. what you expected. what you actually got.

Yes, it takes 10 minutes of your life to provide the information. But you will get an accurate reply. Possiibly even from Bodmer.

Your product link provides some good information. However, I would not recommend the LCDWIKI library software. Life will be easier with TFT_eSPI library. It wass designed for ESP32 and ESP8266.


My unconditional apologies David.

  1. Paste your “User_Setup.h” <DT: Attached>
  2. Post a schematic or photo of your actual wiring. <DT: Attached. Didn’t have the LCD footprint, so quickly made it up with just images>
  3. Quote which library example you are using. <DT: I’m using TFT_eSPI library v1.4.11>
  4. Explain your problem i.e. what you expected. what you actually got. <DT: I intend to use the LCD along with the touch pad for my project. As explained, I got the LCD to work, but I can’t get the Touch to work yet, and hence my query/post here>

User_Setup.h (12.9 KB)

I also tried with this below attached configuration. With the below, LCD continues to work but touch doesn't. I tried the "Test_Touch_Controller" example from the TFT_eSPI library itself, and I couldn't get any touch inputs seen on the serial port.


Go on. You should connect (Slave) SDO and (Slave) T_DO to (Master) MISO And SDI, T_DIN to (Master) MOSI

MOSI means Master-Out, Slave-In MISO means Master-In, Slave-Out

Your User_Setup.h "looks" ok. Especially if all the examples display correct colours, directions, ...

Thankyou David for your inputs. I did try that already. Check my post

deepak4you: Here's what we did:

  1. Connected SCK <-> T_CLK <-> ESP32_PIN18
  2. Connected SDI(MOSI) <-> T_DIN <-> ESP32_PIN23
  3. Connected SDO(MISO) <-> T_OUT <-> ESP32_PIN19
  4. Connected T_CS <-> ESP32_PIN21

This, along with the existing connections for the LCD part.

When we made these connections, the LCD just went blank with only the backlit illuminated. Since that was my understanding of the connections and it did not work, hence I put a query here.

You think there's something wrong with the connections? Or maybe I should use an external power supply? Might be the LCD module is falling short of power when sourced from USB port only?

You appear to be using the default wiring. (Always a good idea to use the Author's default)

Personally, I use:

#define ILI9341_DRIVER
#if defined(ESP32)
// For ESP32 Dev board (only tested with ILI9341 display)
// The hardware SPI can be mapped to any pins

#define TFT_MISO 19
#define TFT_MOSI 23
#define TFT_SCLK 18
#define TFT_CS    5 //15  // Chip select control pin
#define TFT_DC    13 //2  // Data Command control pin
#define TFT_RST   12 //4  // Reset pin (could connect to RST pin)
//#define TFT_RST  -1  // Set TFT_RST to -1 if display RESET is connected to ESP32 board RST

#define TOUCH_CS 25 //21     // Chip select pin (T_CS) of touch screen

//#define TFT_WR 22    // Write strobe for modified Raspberry Pi TFT only

We really need to see a real photo of your wiring. I am 100% certain that Bodmer's wiring is 100% tested.

I can only report my experience i.e. my wiring works for me. I use the same wiring with ESP8266, Teensy3.2, Nucleo, ...


So i tried below:

  1. Did the connections again for LCD and touch. See attached.
  2. Ran the Read_User_Input example and got the output below
TFT_eSPI ver = 1.4.5
Processor    = ESP32
Frequency    = 240 MHz
Transactions = Yes 
Interface    = SPI 
Display driver = 9341
Display width  = 240 
Display height = 320 

MOSI    = D23 (GPIO 23)
MISO    = D19 (GPIO 19)
SCK     = D18 (GPIO 18)
TFT_CS   = D15 (GPIO 15)
TFT_DC   = D2 (GPIO 2)
TFT_RST  = D4 (GPIO 4)

TOUCH_CS = D21 (GPIO 21)

Font GLCD   loaded
Font 2      loaded
Font 4      loaded
Font 6      loaded
Font 7      loaded
Font 8N     loaded
Smooth font enabled

Display SPI frequency = 5.0 MHz 
Touch SPI frequency   = 2.5 MHz
  1. Uploaded the Keypad_240x320 example. The response was as below: 3a. Text popped up on the screen saying "Touch (something something)". Didn't pay much attention 3b. After touching on the corners and few other places, after some 40-50 seconds later, the keypad popped up. And I was elated! 3c. I started pressing the numbers on the screen but nothing happened. I tried with a pen thinking it might work better, but still no response. I left the screen as-is while I was looking at the code and the ckt. Suddenly after a couple of minutes, I saw a button (#7) got pressed automatically and the number (7) appeared on the screen. I continued observing and slowly slowly at random time intervals other numbers started popping up as well. Check the video here to give you a cue of what was happening Touchscreen random response

I restarted many times after that. It seemed as if the many buttons that I had pressed in my first attempt kept popping up on the screen at random times even after multiple reboots. Felt as if the pressed keys (actually the pressed area of the screen) were stored in a non-volatile buffer and was sent/read even after multiple reboots that followed.

I'm happy to see that atleast the touch is working, but so slow that I even a snail would win.

Any cues from this as to what might be going on/what might be wrong?


I ran Examples/Test and Diagnostics/Read_User_Setup/ Result: similar output to you

TFT_eSPI ver = 1.4.5
Processor    = ESP32
Frequency    = 240 MHz
Transactions = Yes 
Interface    = SPI 
Display driver = 9341
Display width  = 240 
Display height = 320 

MOSI    = D23 (GPIO 23)
MISO    = D19 (GPIO 19)
SCK     = D18 (GPIO 18)
TFT_CS   = D5 (GPIO 5)
TFT_DC   = D13 (GPIO 13)
TFT_RST  = D12 (GPIO 12)

TOUCH_CS = D25 (GPIO 25)

Font GLCD   loaded
Font 2      loaded
Font 4      loaded
Font 6      loaded
Font 7      loaded
Font 8      loaded
Smooth font enabled

Display SPI frequency = 27.0 MHz 
Touch SPI frequency   = 2.5 MHz

I ran Examples/320x240/Keypad_240x320 Result: worked fine

I ran Examples/Generic/Touch_Calibrate Result: worked fine

I ran Examples/Generic/On_Off_Button Result: worked fine

I ran Examples/Test and Diagnostics/Test_Touch_Controller/ Result: random x, y, z values until I touch the screen. then I get Z values > 1024 (i.e. pressed) with valid X, Y values. (note these are raw ADC values and not pixel coordinates)

I would not expect anything from your photos. Please post a clear photo showing coloured wires mating with named ESP32 pins.

Although I don't like breadboards, you could plug the TFT into one side with the ESP32 plugged into the other side. I would trim solid coloured wires to connect neatly between TFT and ESP32. Take a photo of neat wiring. Every reader can check your wiring.

At least you have a 3.3V screen with a 3.3V ESP32. Much better than people fiddling with 5V Uno and level shifters.

Personally, I make custom shields with Protoshield pcbs with soldered headers to receive the TFT. I can then use the "custom shield" with any Arduino-style board e.g. Due, Zero, STM32, ..., TTGO ESP32, R1 D1 ESP8266


So it seems it worked finally for me as well.

What I had done initially was that I had reduced the LCD SPI frequency to 5MHz or 10MHz. For some reason, I was trying to run the LCD at a lower SPI frequency, but still touch would not work. I even tried to reduce the touch frequency, even that did not work.

After all these discussions here and my last experience where I would get delayed touch inputs, I set the LCD SPI frequency to 40MHz and Touch SPI frequency set the default 2.5MHz. And that seems to have worked!

I tried to get raw readings from the touchpad and that seemed to work but the keypad did not work. I think i'll have to reset the calibration in the code and start the process all over again to see if it is working fine.

x: 0     y: 3640     z: 79 
x: 0     y: 3568     z: 111 
x: 26     y: 3368     z: 49 
x: 0     y: 2991     z: 118 
x: 260     y: 3343     z: 64 
x: 0     y: 3695     z: 176 
x: 0     y: 3743     z: 113 
x: 0     y: 3647     z: 90 
x: 1471     y: 1891     z: 1310 
x: 0     y: 3742     z: 177 
x: 0     y: 3614     z: 148 
x: 0     y: 3623     z: 180 
x: 0     y: 3719     z: 51 
x: 0     y: 3680     z: 87 
x: 2655     y: 2087     z: 1084 
x: 0     y: 3712     z: 86 
x: 0     y: 3648     z: 96 
x: 1888     y: 2959     z: 1438 
x: 0     y: 3704     z: 91 
x: 2687     y: 2684     z: 1817 
x: 2272     y: 2416     z: 1054 
x: 0     y: 2928     z: 109 
x: 3132     y: 2823     z: 1699 
x: 258     y: 3369     z: 80 
x: 0     y: 3703     z: 101 
x: 95     y: 3681     z: 156 
x: 0     y: 3584     z: 84 
x: 0     y: 3715     z: 133 
x: 0     y: 2928     z: 30 
x: 0     y: 3135     z: 158 
x: 0     y: 2944     z: 56 
x: 20     y: 3439     z: 84 
x: 37     y: 3452     z: 18 
x: 0     y: 3703     z: 82

I really don't understand what the issue was from the beginning, but it looks like everything worked with the standard configuration mentioned in the library itself.

The one thing surely that did not work was the 36pin NodeMCU-32S version of ESP32 dev board. That we checked multiple times on multiple board and did not work with the 36pin version board.

I'll still provide an update once I test the keypad code as well.

Regards, Deepak

Think about it. Random jumper wires with loose connections will never work reliably.

Use regular square header pins with mating sockets. Stationary solid-core wires are fairly good. Or use soldered wires which should be the best.

Remember that the ESP32 is a fast processor. It will respond to glitches that a 16MHz Uno would ever notice.


So keypad worked as well.

I think I know what happened. Since the code wasn't working on the 36pin version of the board, we kept trying different things, one of them being changing the SPI frequency.

About the wiring. We tried the breadboard initially, but with the 36pin board. And the code was still not working. Hence to eliminate any breadboard issues, we decided to hard-solder the pins. And hence we used male-female berg jumpers to do the 3 SPI connections from the LCD part to the touch part. To ensure the connections were clean, we soldered the male part of the berg pin to the board (LCD pins), and the female part slid easy and clean on the touch part. Didn't leave any possibility of a bad connection/connector.

When we used the 30pin board, all worked ok as it was supposed to be.

Apologies if this thread led to nothing. Thankyou David, ketineni and Bodmer himself to have made our lives a luxury by providing this library.

The SPI frequency should not be critical. An ILI9341 works well at 27MHz. It even works at 42MHz (as used by Marek's ILI9341_due library)

I tend to run at 8MHz or 4MHz when debugging because a cheap Logic Analyser will not be much good > 12MHz