Announcement: ESP32 Micropython XPT2046 + ILI9341 driver availability

I’ve tested and published a reference XPT2046 + ILI9341 drivers for Micropython ESP32 on dev-6.1 branch:

Usage:

import lvgl as lv
import lvesp32

# Import ILI9341 driver and initialized it

from ili9341 import ili9341
disp = ili9341()

# Import XPT2046 driver and initalize it

from xpt2046 import xpt2046
touch = xpt2046()

By default, both ILI9341 and XPT2046 are initialized on the same SPI bus with the following parameters:

  • ILI9341: miso=5, mosi=18, clk=19, cs=13, dc=12, rst=4, power=14, backlight=15, spihost=esp.HSPI_HOST, mhz=40, factor=4, hybrid=True
  • XPT2046: cs=25, spihost=esp.HSPI_HOST, mhz=5, max_cmds=16, cal_x0 = 3783, cal_y0 = 3948, cal_x1 = 242, cal_y1 = 423, transpose = True, samples = 3

You can change any of these parameters on ili9341/xpt2046 constructor.
You can also initalize them on different SPI buses if you want, by providing miso/mosi/clk parameters. Set them to -1 to use existing (initialized) spihost bus.

On current settings they are both connected to the same SPI bus, 40MHZ for the ILI9341 and 5MHZ for XPT2046.

Both drivers are pure micropython/hybrid drivers.
I found that it was much easier to develop and integrate python drivers than C drivers, and they give good enough performance on ESP32 (~30FPS easily, when the entire screen is refreshed).
Of course, they can be used as a reference if anyone wants to convert them to C and get the maximum performance / minimum power.

I’ve also added an example of touchscreen calibration script, which can be used with both XPT2046 and raw resistive touch drivers.

3 Likes

How does one run the tpcal script? Edit the SPI params and then uncomment the while True: pass at the end and run with pyboard?

Currently tpcal loads ili9341 and xpt2046 on esp32, so you would have to change it to run on pyboard. (Even on esp32 you would probably want to configure the correct pins)
Pyboard is stm32 right? stm32 is supported but I’m not sure about the specific display and touch drivers. Recently STM32F7DISC drivers were added.

You don’t need to uncomment the ‘while True’ if you are running it from the REPL.

After calibration it would print the calibration values to console. I originally planned to write it to file and let the driver load that file by default, but I never got to doing that.

I’m using esp32, the problem I have is that nothing keeps calling touch.read()… there’s something I’m missing to keep the UI “running”…

Let’s continue the discussion on What calls touch.read() for xpt2046?