Go Down

Topic: Using touch on 2.8 inch ILI9341 LCD with ESP32 (Read 1 time) previous topic - next topic


Jun 08, 2019, 06:21 pm Last Edit: Jun 08, 2019, 06:23 pm by david_prentice
I ran Examples/Test and Diagnostics/Read_User_Setup/
Result:  similar output to you
Code: [Select]

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.
Code: [Select]

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.



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



Thanks David. I am also unsure what caused the issue, but it did. Fortunately that issue is resolved, but I've hit a wall with another issue with the same display - using LCD+Touch on HSPI port and rest of my peripherals on the VSPI port. That is not working and I just started a thread here for the same. Hope I get a resolution to this as well.


Go Up