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.

2 Likes