import lvgl as lv
import espidf as esp
from ili9XXX import *
import machine
import time
from xpt2046 import xpt2046
from micropython import const
machine.freq(80000000)
LANDSCAPE = const(-2)
def yes_callback(event):
print(“Pressed Yes”)
Initialize ILI9341 display with proper SPI configuration
disp = ili9341(miso=5, mosi=18, clk=19, cs=13, dc=12, rst=4, power=14, backlight=15, backlight_on=1, power_on=1,
spihost=1, spimode=0, mhz=15, factor=4, hybrid=True, width=240, height=320, start_x=0, start_y=0,
colormode=COLOR_MODE_BGR, rot=PORTRAIT, invert=False, double_buffer=True, half_duplex=True,
asynchronous=False, initialize=True, color_format=lv.COLOR_FORMAT.RGB565, swap_rgb565_bytes=True
)
Use VSPI_HOST for the XPT2046 touch driver to avoid conflicts
touch = xpt2046(
spihost=1, # Use VSPI_HOST to avoid conflict with HSPI_HOST
half_duplex=False ,
mhz=5, # Set to 2 MHz for stable operation
max_cmds=16,
cal_x0=3783, cal_y0=3948, cal_x1=242, cal_y1=423,
transpose=False,
samples=3
)
Create a screen and apply a style
scr = lv.screen_active()
style = lv.style_t()
style.init()
style.set_bg_color(lv.color_hex(0x000000)) # Set background color to black
scr.add_style(style, 0)
Create a “Yes” button
btn_yes = lv.button(scr)
btn_yes.set_size(80, 50)
btn_yes.align(lv.ALIGN.CENTER, 0, 0) # Center the button on the screen
btn_yes.add_event_cb(yes_callback, lv.EVENT.CLICKED, None) # Attach callback for the “Yes” button press
Add a label to the “Yes” button
label_yes = lv.label(btn_yes)
label_yes.set_text(“Yes”)
label_yes.center()
Load the screen
lv.screen_load(scr)
print(“Setup complete”)
i tried to change spi but resulted in spi initialization error , kindly help me with this problem