LVGL 7.7.1 running on a screen but how to add a touchscreen driver

What MCU/Processor/Board and compiler are you using?


What LVGL version are you using?


What do you want to achieve?

I have a parallel screen working under TFT esp but it doesn’t allow me to handle a spi touchscreen so I wanted to let lvgl do that part with a XPT2046 and I would like to learn how to config also a TFT screen from the driver list in lvgl instead to use tft esp one.

What have you tried so far?

I first tried with LV_arduino 3.0.1 but I am not really getting help with that. I got errors and I try the and the to get the XPT2046 to work without any result. On the readme website, it only helps to get it to work with the selection screen but that is not in the Arduino environment and has to config the files by hand + in the readme it only helps if you have the basic tft esp screen is accepted.

So you probably need some library for XPT2046. Because you didn’t put any info about your hardware (even in your another post here LV_Arduino-3.0.1 esp32 add xpt2046 with a parallel screen) - for example used/free gpio, used module (wroom/wrover/???), nobody can suggest any working one - you have to search for it and make it working by yourself. After you get LVGL library working and XPT2046 library working we can help you to move further. As embeddedt wrote you for the first question - error you have posted came not from lv_drivers so it seems like it is specific to your environment - again, you didn’t post any info about your environment, installed libraries, installed core version, … so only you can search and find the source of the problem.

1 Like

So you probably need some library for XPT2046 I saw that this link had them. and the

for example used/free gpio, used module (wroom/wrover/???)
I used ESP32 TTGO T8 16mb. I Might think focus first on the touchscreen because the tft screen works in parallel from out the TFT esp now. It would be nice to have tft esp lib to work with the screen but parallel and spi don’t compile.

I use the 7 inch SSD1963 screen

Screen pins are
TC_S pin 21
T_DO pin 19
T_DIN pin 23
T_CLK pin 18

I use Arduino IDE 1.8.12 I use now LVGL V7.7.1 and the other called LV_Arduino-3.0.1 because that is the last one.

I hope that this helps now? for learning, other screens without TFT_ESP lib can be checked after that. Or is it possible to let TFT_esp handle the spi touchscreen with the parallel screen would be better if somebody knows how to do that?

Hmm, still not very helpfull - you wrote that the LCD has parallel interface. Does your explanation mean that the SSD1963 uses (some) another pins and the XPT2046 is connected to GPIO 21, 19, 23 and 18? If so you have to search for Arduino XPT2046 library - there is plenty of them, some are also listed in official Arduino library repository (did you look here? ). You have to choose one, which suits your needs and try to make it work. After you choose one and make it work (and solve the calibration) we can guide you of how to write driver input to the LVGL.

As @Pablo2048 mentioned, please try to get the touch to work independently of LVGL first, as this does not appear to be an LVGL-specific problem.

Yes, exactly - imagine that the TFT_eSPI is here just as an ultra-fast disply driver, LVGL is… well LVGL :slight_smile: , supported by TFT_eSPI. For the touch support in LVGL you need some library (at the same level as TFT_eSPI) integrated into your sketch. After every piece is working alone we can help you to glue all this together.

Does your explanation mean that the SSD1963 uses (some) another pins and the XPT2046 is connected to GPIO 21, 19, 23 and 18?
Yes, because parallel doesn’t use SPI pins and also yes GPIO are connected to the XPT2046 pins also mentioned which one. nothing else is connected on this pins yet. and the this lib has them. But I didn’t get them to work. because they are ported for the LVGL and I am not sure how to implement them yet. In the readme file helps to use TFT esp lib and yes I already have other rpi screen working with it but that screen is totally handled by TFT esp lib. Only problem for me now is that parallel tft configuration can’t be handle with the SPI touchscreen together yet. So for now I try to get it to work wit LVGL but use external configuration is unknown for me. documentation to use TFT esp make good sense for me. What I understand I have to change indev_drv.read_cb. For what I see this lib has most option under indev directory. maybe also in the future the display drivers.

Hope you can help me with some hints or direction to add this.

Those libraries are not meant to be used in Arduino environment IMHO so that is why I suggest you to search for “native” Arduino library…

I am confused also this one not because those where made for Arduino i thought? or the Arduino demo is for other use?

Why are so confused? There is clearly stated that this library is for Esperssif IDF and Arduino is not mentioned at all…

I thought it was compatible with it because it was written for esp32 and LVGL. So I need a other way to get it to work. Hmmm so that was not clear for me and that was the confused part from it. So there is no arduino drivers for the xpt2046 lib yet for LVGL?

I think that the LVGL is driver-agnostic (which is absolutely perfect IMO) so there needs to be written drivers (or libraries in the Arduino world) with some glue code. TFT_eSPI is one of them. When I wrote lvgl arduino port I was too lazy and I did have very good experience with the TFT_eSPI s I’ve used it in the example. There was once upon a time discussion here , but I was short of time. Anyway you can use any Arduino XPT2046 library if it:

  1. work on your platform (ESP32 here)
  2. suit your hardware connections

I think that I have to explain point 2 little bit more:
I don’t know exactly how your parallel interface work - I’m not sure that the ESP32 has enough GPIOs to drive it directly so maybe you use some SPI->GPIO extender. If this is your case you have to choose xpt library which allows you to specify SPI instance, or uses SPI transactions (in case of shared SPI).
So to answer your question - maybe there is library, which can be directly used with LVGL, but is depends on your hardware. Anyway you have to write some glue code to made it work with LVGL same way, as I wrote the code for TFT_eSPI. With the glue code we can help you…

1 Like

The parallel screen is driven with 8bit data-line instead 16bit. so that is possible without a io-expander. Problem is that tft_espi can’t handle parallel and spi configuration now. That would be better but for now I also want to know how to select your own hardware in lvgl. I have xpt2046 working with rpi screen, but they both got driven by spi. Only this moment my screen is driven by parallel and my touchscreen still on spi.

There is no problem at all then - do as I and @embeddedt suggested - find the xpt2046 library for Arduino platform and ESP32 target and make it work on your hardware. After that we can help you to write the glue. There is nothing we can do otherwise.

I don’t have a SSD1963 display, but in my experience TFT_eSPI only needs an additional Chip Select on the SPI bus and optionally a lower frequency for the XPT2046 chip:

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

// The XPT2046 requires a lower SPI clock rate of 2.5MHz so we define that here:
#define SPI_TOUCH_FREQUENCY  2500000

When TOUCH_CS is defined, TFT_eSPI will use its built-in XPT2046 driver:

// Load the Touch extension
#ifdef TOUCH_CS
  #include "Extensions/Touch.h"        // Loaded if TOUCH_CS is defined by user

Can you share your user_setup file?

Trust me. when you select a parallel screen SPI touchscreen can’t be compiled anymore. Only way to solve that comment TOUCH_CS. So external lib is needed for the touchscreen. Also TFT_espi knows it.

Looks like this lib is a good one. I have it now working but still need to calibrate the screen with the right value’s.

How can I add this etouch lib in LVGL so LVGL can pick it up @Pablo2048 ?

I have used XPT2046_Touchscreen before and it can be integrated with lv_drivers too like so: XPT2046.cpp. We’ve used it on STM32duino though, but the codebase should be good for ESP Arduino too…

Do you have a link to that display you are using on ESP32? It looks awesome.

Take the inspiration from here (Its old, but it shows the way to go), just replace tft.getTouch with .getXY() (calibration has to be done separately).

1 Like

I don’t have the link anymore but if you look it up ssd1963 7inch, 5 inch or 4.3inch you can find it easy. Keep in mind that this is still in development and voltage levels. It looks like plenty of things need still to be glued to get it to work altogether.

and @Pablo2048 thanks I will look it up and also @fvanroie will check what you had.

@Pablo2048 that did the trick. Had to change somethings, but also had some older experience from RPI screen on SPI with LVGL. I would say SPI screens are much better to use. The problem is I didn’t find a good spi screen with 7inch or bigger. I can say the spi screens have a faster refresh rate because the parallel screen is pretty slow.