LVGL with ILI9341 + Touch panel

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
User avatar
spookyrufus
Posts: 12
Joined: Wed Jul 15, 2020 8:09 am
Location: Estonia
Contact:

LVGL with ILI9341 + Touch panel

Post by spookyrufus » Mon Jan 25, 2021 7:41 pm

I am trying to experiment with LVGL and an ILI9341 + touch display.
So far I managed to compile and deploy Micropython+LVGL and get the display connected via VSPI to the ESP32, and get some demos running. I am amazed at the beauty of the results, using only few lines of python code.
I am having trouble though, getting the touch panel working.

Image

First, I am not sure of the correct wiring for the touch panel. On the back of the display module, the first 5 pins are dedicated to the touch functions:
Image

How should these connect to the ESP32?
I have tried several ways of connecting it, but also due to the second point below, I am not sure whether I got the right wiring, and the wrong test routine, or the other way around, or both.

And second, I could not find -despite extensive searches- any example code to test whether the connected touch panel is working, in LVGL.
I took few educated guess after reading the docs, but no good results.

I would appreciate any pointer in the right direction.
Shameless shoutout to @pythoncoder or @dhylands because they are legends and absolute divinities of these forums :D

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: LVGL with ILI9341 + Touch panel

Post by Roberthh » Mon Jan 25, 2021 8:03 pm

Ar you sure that a touch sensor is present. The chip U2 seems missing. And if yes, which touch controller should be there?
Edit: On some other pictures I see a XPT2048 populated at that place.

tft.jpg
tft.jpg (126.15 KiB) Viewed 6839 times

Divergentti
Posts: 67
Joined: Fri Sep 04, 2020 9:27 am
Location: Hanko, Finland
Contact:

Re: LVGL with ILI9341 + Touch panel

Post by Divergentti » Tue Jan 26, 2021 7:57 am

Most likely it is missing.

Code you might be interested https://github.com/divergentti/airquali ... ouchscreen most likely better display drivers exists, but I used that. I hit into memory issues and decided to leave keyboard etc interaction with user away.

Connections in the parameters.py file https://github.com/divergentti/airquali ... ameters.py

My similar TFT panel with Touchscreen version:


Image

Image

Image


Currently I wonder can I use SD-slot as a slave to SPI-bus, because another SPI is in touchcreen and another in TFT...

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: LVGL with ILI9341 + Touch panel

Post by Roberthh » Tue Jan 26, 2021 9:57 am

You can connect several SPI slaves to the same SPI BUS. Just activate them alternatively with CS. You may have to switch speed.

Divergentti
Posts: 67
Joined: Fri Sep 04, 2020 9:27 am
Location: Hanko, Finland
Contact:

Re: LVGL with ILI9341 + Touch panel

Post by Divergentti » Tue Jan 26, 2021 11:37 am

Roberthh wrote:
Tue Jan 26, 2021 9:57 am
You can connect several SPI slaves to the same SPI BUS. Just activate them alternatively with CS. You may have to switch speed.
Thank you @Roberthh for this information.

Currently I am using 1.2 MHz for the touchscreen digitizer (VSPI) and I guess 1.31250 MHz is something what I shall use for the SD-reader? The touchscreen absolutely maximum speed is below 2 MHz with my test setup (with dupont patch cables).

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: LVGL with ILI9341 + Touch panel

Post by Roberthh » Tue Jan 26, 2021 12:52 pm

It might be easier to share the bus for display and touch screen. For the SD card, it may not be clear about when the SD card will be accessed. Then you have to switch the bus speed between accesses. Besides that, you may also consider using SoftSPI for the touch interface. That is not in conflict with the other interfaces. If you use different buses, you can pull CS permanently low, reducing pin count.

Long ago, I have also made a driver for the XPT2048 using Pin bit-banging. See: https://github.com/robert-hh/XPT2046-to ... yBoard.git
The function to adapt is touch_talk(). It uses direct port I/O of the Pyboard. Your can change that to ESP32, or use Pin access. No too complicated.

User avatar
spookyrufus
Posts: 12
Joined: Wed Jul 15, 2020 8:09 am
Location: Estonia
Contact:

Re: LVGL with ILI9341 + Touch panel

Post by spookyrufus » Tue Jan 26, 2021 2:01 pm

Wow. Missing chip indeed.
Thanks for pointing that out as I would have never figured it out.

User avatar
spookyrufus
Posts: 12
Joined: Wed Jul 15, 2020 8:09 am
Location: Estonia
Contact:

Re: LVGL with ILI9341 + Touch panel

Post by spookyrufus » Tue Jan 26, 2021 4:08 pm

Divergentti wrote:
Tue Jan 26, 2021 7:57 am
Most likely it is missing.

Code you might be interested https://github.com/divergentti/airquali ... ouchscreen
Thanks for this pointer also.
I have ordered a new display from AliExpress (unfortunately there aren't many for sale where I live and shipping from Amazon is outrageous) so I have now around 3 weeks to review your code before I can test it :D

Divergentti
Posts: 67
Joined: Fri Sep 04, 2020 9:27 am
Location: Hanko, Finland
Contact:

Re: LVGL with ILI9341 + Touch panel

Post by Divergentti » Tue Jan 26, 2021 4:19 pm

spookyrufus wrote:
Tue Jan 26, 2021 4:08 pm
Divergentti wrote:
Tue Jan 26, 2021 7:57 am
Most likely it is missing.

Code you might be interested https://github.com/divergentti/airquali ... ouchscreen
Thanks for this pointer also.
I have ordered a new display from AliExpress (unfortunately there aren't many for sale where I live and shipping from Amazon is outrageous) so I have now around 3 weeks to review your code before I can test it :D
Hopefully 3 weeks is enough. I ordered quite a lot sensors and stuff from Aliexpress October 2020 and I am still waiting some of them. Reason is most likely Post of Finland, because European Union begins collecting VAT and customs from purchases less than 22€ and they hold those packages somewhere. Last year they did not collect VAT nor customs from purhcases valued less than 22€. At least tracking code shows package arrivals to Finland already November or beginning of December.

About my code: I hit into serious memory issues and I re-structured and refactored it quite a bit. I removed comments, shortened variable names etc.

For some reason speeding up CPU to 240MHz seems to keep free memory around 40 000, but if I use standard 160MHz, free memory might dip almost 0 and sometimes I got out of memory.

Once memory issue is solved, most likely I add some trending, average calculation, finish MQTT part, perhaps add SD-card access to the code and then I draw some nice case with Fusion360 to be printed with 3D-printer https://www.thingiverse.com/divergentti/designs.

User avatar
spookyrufus
Posts: 12
Joined: Wed Jul 15, 2020 8:09 am
Location: Estonia
Contact:

Re: LVGL with ILI9341 + Touch panel

Post by spookyrufus » Tue Jan 26, 2021 8:07 pm

Divergentti wrote:
Tue Jan 26, 2021 7:57 am
Reason is most likely Post of Finland
What are the chances.. I'm across the gulf, in Tallinn. Terve fellow micropythonist!

Post Reply