Modulo Esp32-2432S08 (ili9341+xpt2046) problem touch

Hello everyone, I have encountered the following issue. I have compiled the firmware for the ESP32-2432S08 module , and I have managed to get the display working, but I am unable to make the touchscreen function. Here is my code:

import lvgl as lv
import espidf as esp

from ili9XXX import ili9341
from xpt2046 import xpt2046

lv.init()


disp = ili9341(spihost=esp.HSPI_HOST, miso=12, mosi=13, clk=14, cs=15, mhz=10, width=240, height=320, dc=2, rst=-1, power=-1, factor=8, backlight=21, backlight_on=1)

touch = xpt2046(miso=39, mosi=32, cs=25, spihost=esp.HSPI_HOST, mhz=5, max_cmds=16)

scr = lv.obj()
btn = lv.button(scr)
btn.align(lv.ALIGN.CENTER, 0, 0)
label = lv.label(btn)
label.set_text('Hello World!')
lv.screen_load(scr)
    

It produces the following error.:

Traceback (most recent call last):
File “main.py”, line 13, in
File “xpt2046.py”, line 29, in init
AttributeError: ‘lv_display_t’ object has no attribute ‘get_hor_res’

I hope you can help me. Thank you.

Hello!
That’s a bug in that file. There were renamings in LVGL (v8 → v9), and some of these renamings are not applied to MicroPython binding.
I will fix it, and check other files, too.
Thanks for reporting it!

Bug fixed (PR: update lv_bindings by PGNetHun ¡ Pull Request #79 ¡ lvgl/lv_micropython ¡ GitHub )

Please pull again lv_micropython, rebuild, and check whether it works.

Thank you for your solution, that problem was fixed. But I have another problem with the touch xpt2046, I can’t get it to work

import lvgl as lv
import espidf as esp

lv.init()

# Import ILI9341 driver and initialized it

from ili9XXX import ili9341
disp = ili9341(miso=12,
               mosi=13,
               clk=14,
               cs=15,
               dc=2,
               rst=-1,
               power=-1,
               backlight=21,
               backlight_on=1,
               spihost=esp.HSPI_HOST,
               spimode=0,
               width=240,
               height=320,
               mhz=40,
               factor=4,
               hybrid=True,
               half_duplex=True,)

# Import XPT2046 driver and initalize it

from xpt2046 import xpt2046
touch = xpt2046(miso=39,
                mosi=32,
                clk=25,
                cs=33,
                spihost=esp.HSPI_HOST,
                mhz=2,
                max_cmds=16,
                cal_x0 = 3783,
                cal_y0 = 3948,
                cal_x1 = 242,
                cal_y1 = 423,
                transpose = True,
                half_duplex=True,
                samples = 3)

def button_cb(e):
    print(f"lv.EVENT: {e.get_code()}")


scr = lv.obj()
btn = lv.button(scr)
btn.align(lv.ALIGN.CENTER, 0, 0)
label = lv.label(btn)
label.set_text('Hello World!')
lv.screen_load(scr)
    

I’m getting the following error. I’ve tried all the possible combinations but I can’t find the solution. I see the button on the screen but I don’t have touch

E (1340) spi: spi_bus_initialize(756): SPI bus already initialized.
Traceback (most recent call last):
File “main.py”, line 35, in
File “xpt2046.py”, line 58, in init
File “xpt2046.py”, line 113, in spi_init
RuntimeError: Failed initializing SPI bus

I hope you can guide me. Thank you

Change the host for the touch driver to VSPI. You are trying to initialize 2 different busses to the same host and that’s not gonna work.

I have the same module//problem as the oirginal poster. Changing spihost=esp.HSPI_HOST to spihost=esp.VSPI_HOST for the display (ili9341) still produces the spi init error. Since the board is a fixed wired combo with an esp32 (the so called ‘the cheap yellow display’), we have to live with 2 separate SPI busses. Any more ideas what to do?

The solution is to use the lvgl patch that hasnt been merged yet:

You need to cd into the lib/lv_bindings directory and type:

gh pr checkout 340

(sudo apt install gh and authorizing your github account may be needed)
Then get out of your lv_micropython, and build it again, deploy it in the ESP32-2432S08

Then, change the python code above to:

import lvgl as lv
import espidf as esp

lv.init()

# Import ILI9341 driver and initialized it

from ili9XXX import ili9341

disp = ili9341(miso=12,
               mosi=13,
               clk=14,
               cs=15,
               dc=2,
               rst=-1,
               power=-1,
               backlight=21,
               backlight_on=1,
               spihost=esp.HSPI_HOST,
               spimode=0,
               width=240,
               height=320,
               mhz=40,
               factor=8,
               hybrid=True,
               half_duplex=True,)

# Import XPT2046 driver and initalize it
from xpt2046 import xpt2046_softspi as xpt2046
touch = xpt2046(miso=39,
                mosi=32,
                clk=25,
                cs=33,
                spihost=esp.VSPI_HOST,
                mhz=2,
                max_cmds=16,
                cal_x0 = 3783,
                cal_y0 = 3948,
                cal_x1 = 242,
                cal_y1 = 423,
                transpose = True,
                half_duplex=True,
                samples = 3)

def button_cb(e):
    print(f"lv.EVENT: {e.get_code()}")

scr = lv.obj()
btn = lv.button(scr)
btn.align(lv.ALIGN.CENTER, 0, 0)
label = lv.label(btn)
label.set_text('Hello World!')
lv.screen_load(scr)

Remember to reset your board first, to prevent low DMA errors.

Refer to this solution to change to landscape

1 Like

Thank you very much - there is progress! I manually copied over the new files and recompiled the project. The DMA error message is gone and touch works. I had to change width and height in the init code and set transpose to False to make it work:

import lvgl as lv
import espidf as esp

lv.init()

# Import ILI9341 driver and initialized it

from ili9XXX import ili9341

disp = ili9341(miso=12,
               mosi=13,
               clk=14,
               cs=15,
               dc=2,
               rst=-1,
               power=-1,
               backlight=21,
               backlight_on=1,
               spihost=esp.HSPI_HOST,
               spimode=0,
               width=320,
               height=240,
               mhz=40,
               factor=8,
               hybrid=True,
               half_duplex=True,
               rot=0)

# Import XPT2046 driver and initalize it
from xpt2046 import xpt2046_softspi as xpt2046
touch = xpt2046(miso=39,
                mosi=32,
                clk=25,
                cs=33,
                spihost=esp.VSPI_HOST,
                mhz=2,
                max_cmds=16,
                cal_x0 = 3783,
                cal_y0 = 3948,
                cal_x1 = 242,
                cal_y1 = 423,
                transpose = False,
                half_duplex=True,
                samples = 3,
                
                )

def button_cb(e):
    print(f"lv.EVENT: {e.get_code()}")

scr = lv.obj()
btn = lv.button(scr)
btn.align(lv.ALIGN.CENTER, 0, 0)
btn.add_event_cb(button_cb,lv.EVENT.ALL, None)
label = lv.label(btn)
label.set_text('Hello World!')
lv.screen_load(scr)

``

I am glad it helped… in my case, landscape works with:

...
from ili9XXX import LANDSCAPE,REVERSE_LANDSCAPE,PORTRAIT,REVERSE_PORTRAIT
...
disp = ili9341(miso=12,mosi=13,clk=14,cs=15,dc=2,rst=-1,
               power=-1,backlight=21,backlight_on=1,
               spihost=esp.HSPI_HOST,spimode=0,
               width=320,height=240,rot=LANDSCAPE,
               mhz=40,factor=8,hybrid=True,half_duplex=True,)

And I need to swap x0 with x1 and y0 with y1.

But rot=0 gives me a garbled screen… your whole example gives me a garbled screen too.

interesting…What board do you have? I have the more recent 2.8inch version with usb-c (ESP32-2432S028), I also encountered the garbled screen with some settings I tried. Do you happen to know how to switch to Portrait mode? With the Arduino LVGL version there is a runtime method lv_disp_set_rotation(disp, LV_DISP_ROT_270) that I can use, but this seems not to be present in the mpy version.

Have you the MicroPython binding that I have been working on? It compiles using IDF 5.2.0 and MicroPython 1.23.0 and it supports SPI, I8080, RGB and LED Matrix displays. It supports using DMA memory for all the display types. There is a decent number of display drivers and touch drivers built into it and it even supports RGB displays that have low speed 3 wire SPI for configuring the display.

There is a display driver framework as well as a touch driver framework which makes adding new drivers a breeze.

The SPI bus is able to be shared so using an SPI display and SPI touch is not a problem SD Card readers work as well.

The best part is you do not need to really do anything to build. It compiles on both Linux and macOS. Install the build essentials, cmake and python3 and using a single command it will collect all requirements and compile it for you. It even makes a single binary file that has to be flashed instead of 3.

The ports it compiles on right now is ESP32 and Unix. STM32 and RP2 I have to correct a couple of things with.

OH… and I forgot to mention. It automatically takes care of setting the partition sizes too.

Use

from ili9XXX import LANDSCAPE,REVERSE_LANDSCAPE,PORTRAIT,REVERSE_PORTRAIT

and rot=PORTRAIT or rot=1 in the disp=ili9341(…) line

I use the first version of ESP32-2432S028, with micro-USB port

kdschlosser, I used the instructions in GitHub - lvgl/lv_micropython: Micropython bindings to LVGL for Embedded devices, Unix and JavaScript

Does your lvgl_micropython use LVGL9?

It uses the master branch of the LVGL repo at the moment. When I do a release I will lock it to the latest release of LVGL.

That being said. It shouldn’t be too much of an issue to change LVGL to a lower version if needed. It’s easy for me to upgrade or downgrade LVGL and MicroPython.

Also. The rotation you can set whenever you want and it will automatically adjust the touch accordingly. There is also calibration for the touch screen that is built in. The calibration data doesn’t need to be hard coded and the data is persistent between restarts of the ESP32.

It also supports backlight dimming if the display supports it.
You can also overclock the flash and PSRAM to 120 mhz (240 mhz if it is octal flash and octal PSRAM) if you are using the ESP32-S3

In case it helps anyone:
I also had issues with the Cheap-Yellow-Display with two usb-ports and I’ve uploaded some working demos here. I finally got the right color mode, display rotation and touch driver.

Read the information, the demo relies on a precompiled firmware and a modified touch driver from an external blog. I have provided the links in the github readme.