ESP32 2432S028 - can't get inputs from the touch driver xpt2046

Hello everyone!

This question is frequently asked, but none of the provided answers worked for me.

I’ve got ESP32 2432S028 board - link and want to get the touch response.

This is my main.py script. I left in the comments some of the approaches I’ve tried for reference.

import sys

from machine import Pin, SPI

from ili9XXX import ili9341
import lvgl as lv
lv.init()

disp = ili9341(clk=14, cs=15, dc=2, rst=12, power=23, backlight=21, miso=12, mosi=13,rot=0x20,width=320, height=240,backlight_on=1)

spi2=SPI(2,baudrate=2500000,mosi=Pin(32),miso=Pin(39))

from xpt2046 import xpt2046
touch = xpt2046(spihost=2,clk=25,cs=33)
# touch = xpt2046()
# touch = xpt2046(cs=5)
# touch = xpt2046(cs=21)
# touch = xpt2046(cs=33)
# touch = xpt2046(spihost=1,cs=36)
# touch = xpt2046(spihost=2, cs=5)
# touch = xpt2046(spihost=2,cs=33)
# touch = xpt2046(spihost=2,clk=25,cs=33)
# touch = xpt2046(spihost=2,mosi=32,miso=39,clk=25,cs=33)
# touch = xpt2046(cal_x0=3799, cal_x1 = 353, cal_y0=220, cal_y1 = 3719,transpose = False)

print(f"Python version: {sys.version_info}")

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

scr = lv.scr_act()

btn = lv.btn(scr)
label = lv.label(btn)
label.set_text("Button")
btn.align(lv.ALIGN.CENTER,0,0)
btn.add_event(button_cb, lv.EVENT.ALL, None)

lv.scr_load(scr)

Terminal output:

>>> ets Jul 29 2019 12:21:46

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:4344
load:0x40078000,len:13816
load:0x40080400,len:3340
entry 0x40080618
Single buffer
ILI9341 initialization completed
Enable backlight
Python version: (3, 4, 0)
MicroPython v1.20.0-700-g841ece132-dirty on 2023-10-03; ESP32 module with ESP32
Type "help()" for more information.
>>> 
>>> 
MicroPython v1.20.0-700-g841ece132-dirty on 2023-10-03; ESP32 module with ESP32
Type "help()" for more information.
>>> lv.EVENT: 35
lv.EVENT: 45
lv.EVENT: 45
lv.EVENT: 42
lv.EVENT: 45
lv.EVENT: 45
lv.EVENT: 20
lv.EVENT: 45
lv.EVENT: 45
lv.EVENT: 21
lv.EVENT: 27
lv.EVENT: 28
lv.EVENT: 22
lv.EVENT: 23
lv.EVENT: 24
lv.EVENT: 25
lv.EVENT: 26
lv.EVENT: 21
lv.EVENT: 27
lv.EVENT: 28
lv.EVENT: 22
lv.EVENT: 23
lv.EVENT: 24
lv.EVENT: 25
lv.EVENT: 26

>>> 

All of the above lv.EVENTs were displayed during the boot; when I touch the screen, nothing happens.

Any ideas are greatly appreciated!

SET… miso, mosi, clk … I am using spihost=2 which is inline with VSPI_HOST
then SET cs for each device.


From: Quick reference for the ESP32 — MicroPython latest documentation

Try THIS…

import lvgl as lv
from ili9XXX import ili9341
from xpt2046 import xpt2046

disp = ili9341(spihost=2, miso=19, mosi=23, clk=18, cs=15, mhz=10, dc=13, power=-1, rst=-1, factor=8, backlight=27, backlight_on=1)
touch = xpt2046(spihost=2, cs=5)

First of all, thank you for replying to my post!

I tried your code:

disp = ili9341(spihost=2, miso=19, mosi=23, clk=18, cs=15, mhz=10, dc=13, power=-1, rst=-1, factor=8, backlight=21,backlight_on=1)
touch = xpt2046(spihost=2,cs=5)

The display is light, but the button is not shown. Device seams to be hanging:

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:4344
load:0x40078000,len:13816
load:0x40080400,len:3340
entry 0x40080618
Double buffer
ILI9341 initialization completed
Enable backlight
MicroPython v1.20.0-700-g841ece132-dirty on 2023-10-03; ESP32 module with ESP32
Type "help()" for more information.
>>> lv.EVENT: 35
lv.EVENT: 45
lv.EVENT: 45
lv.EVENT: 42
lv.EVENT: 45
lv.EVENT: 45
lv.EVENT: 20
lv.EVENT: 45
lv.EVENT: 45
lv.EVENT: 21
lv.EVENT: 27
lv.EVENT: 28
lv.EVENT: 22
lv.EVENT: 23
lv.EVENT: 24
lv.EVENT: 25
lv.EVENT: 26
lv.EVENT: 21
lv.EVENT: 27
lv.EVENT: 28
lv.EVENT: 22
lv.EVENT: 23
lv.EVENT: 24
lv.EVENT: 25
lv.EVENT: 26

The >>> is not displayed in the terminal.

I tried to combine my display configuration with your touch settings:

disp = ili9341(clk=14, cs=15, dc=2, rst=12, power=23, backlight=21, miso=12, mosi=13,rot=0x20,width=320, height=240,backlight_on=1)
touch = xpt2046(spihost=2,cs=5)

Unfortunately, it results in the following error:

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:4344
load:0x40078000,len:13816
load:0x40080400,len:3340
entry 0x40080618
Single buffer
ILI9341 initialization completed
Enable backlight
E (1540) spi_master: spi_master_init_driver(200): host_id not initialized
Traceback (most recent call last):
  File "main.py", line 11, in <module>
  File "xpt2046.py", line 49, in __init__
  File "xpt2046.py", line 109, in spi_init
RuntimeError: Failed adding SPI device
MicroPython v1.20.0-700-g841ece132-dirty on 2023-10-03; ESP32 module with ESP32
Type "help()" for more information.
>>> 

My source code:

from ili9XXX import ili9341
import lvgl as lv
lv.init()

from xpt2046 import xpt2046

disp = ili9341(clk=14, cs=15, dc=2, rst=12, power=23, backlight=21, miso=12, mosi=13,rot=0x20,width=320, height=240,backlight_on=1)
# disp = ili9341(spihost=2, clk=18, cs=15, dc=2, rst=12, power=23, backlight=21, miso=19, mosi=23,rot=0x20,width=320, height=240,backlight_on=1)
# disp = ili9341(spihost=2, miso=19, mosi=23, clk=18, cs=15, mhz=10, dc=2, rst=12, power=23, backlight=21, rot=0x20,width=320, height=240,backlight_on=1)
# disp = ili9341(spihost=2, miso=19, mosi=23, clk=18, cs=15, mhz=10, dc=13, power=-1, rst=-1, factor=8, backlight=21,backlight_on=1)
touch = xpt2046(spihost=2,cs=5)

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

scr = lv.scr_act()

btn = lv.btn(scr)
label = lv.label(btn)
label.set_text("Button!")
btn.align(lv.ALIGN.CENTER,0,0)
btn.add_event(button_cb, lv.EVENT.ALL, None)

lv.scr_load(scr)

Any further suggestions are much appreciated!

Got pin info from here…
https://github.com/rzeldent/esp32-smartdisplay/blob/main/include/esp32_smartdisplay.h

Display and Touch have separate SPI busses !!!

Give this a try…

import lvgl as lv
from ili9XXX import ili9341
from xpt2046 import xpt2046

lv.init()
disp = ili9341(miso=12, mosi=13, clk=14, cs=15, mhz=50, dc=2, rst=-1, power=-1, factor=8, backlight=21, backlight_on=1)
touch = ili9341(miso=39, mosi=32, clk=25, cs=33, mhz=2)

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

scr = lv.scr_act()
btn = lv.btn(scr)
label = lv.label(btn)
label.set_text("Button!")
btn.align(lv.ALIGN.CENTER,0,0)
btn.add_event(button_cb, lv.EVENT.ALL, None)
lv.scr_load(scr)


disp = ili9341(miso=12, mosi=13, clk=14, cs=15, mhz=50, dc=2, rst=-1, power=-1, factor=8, backlight=21, backlight_on=1)
touch = xpt2046(miso=39, mosi=32, clk=25, cs=33, mhz=2)

Produced the following error:

E (630) spi: spi_bus_initialize(756): SPI bus already initialized.
Traceback (most recent call last):
  File "main.py", line 11, in <module>
  File "xpt2046.py", line 49, in __init__
  File "xpt2046.py", line 103, in spi_init
RuntimeError: Failed initializing SPI bus

I removed the clk parameter from xpt2046. Code executed, but touch is still not responding:

import lvgl as lv
from ili9XXX import ili9341
from xpt2046 import xpt2046

lv.init()
disp = ili9341(miso=12, mosi=13, clk=14, cs=15, mhz=50, dc=2, rst=-1, power=-1, factor=8, backlight=21, backlight_on=1)
# touch = ili9341(miso=39, mosi=32, clk=25, cs=33, mhz=2)
touch = xpt2046(miso=39, mosi=32, cs=33, mhz=2)

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

scr = lv.scr_act()
btn = lv.btn(scr)
label = lv.label(btn)
label.set_text("Button!!")
btn.align(lv.ALIGN.CENTER,0,0)
btn.add_event(button_cb, lv.EVENT.ALL, None)
lv.scr_load(scr)

I also tried this approach, but without any luck:

spi = SPI(2, sck=Pin(25), miso=Pin(39), mosi=Pin(32))
# spi = SPI(2, baudrate=2500000, sck=Pin(25), miso=Pin(39), mosi=Pin(32))
touch = xpt2046(spihost=2)

From
ESP32-2432S028 | macsbug

They have this table…

What I really need is a schematic of this exact board then we can determine what the pins are.

Unfortunately, I was not able to find any schematic. This development board looks very interesting, but the lack of documentation surprised me :frowning:

Okay we’re going to share the display bus with the touch which is on the HSPI =1.

disp = ili9341(spihost=1, miso=12, mosi=13, clk=14, cs=15, mhz=10, dc=2, rst=-1, power=-1, factor=8, backlight=21, backlight_on=1)
touch = ili9341(spihost=1, cs=33, mhz=10)

give it a go,

No errors, but touch does not work :frowning:

One last try… some touch diplays are not very fast… mhz=5

disp = ili9341(spihost=1, miso=12, mosi=13, clk=14, cs=15, mhz=10, dc=2, rst=-1, power=-1, factor=8, backlight=21, backlight_on=1)
touch = ili9341(spihost=1, cs=33, mhz=5)

Does not work :frowning:

I am very grateful for your involvement, @SL2021-Dev . It would be great if we could manage to solve this issue. Thank you so much!