Go Down

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


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!



May 18, 2019, 06:21 am Last Edit: May 18, 2019, 06:22 am by ketineni
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.



One more quick question if someone could help here.

From the product document shared http://www.lcdwiki.com/2.8inch_SPI_Module_ILI9341_SKU:MSP2807 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?



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 :(



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.




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.



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>


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.


Jun 07, 2019, 06:37 pm Last Edit: Jun 07, 2019, 06:40 pm by david_prentice
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
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:
Code: [Select]

#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
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   = 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

3. 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?

Go Up