This sample code throws no SPI errors but mem-allocation errors
Traceback (most recent call last):
File “”, line 7, in
MemoryError: memory allocation failed, allocating 1075011816 bytes
from micropython import const
import lvgl as lv
from machine import Pin, SPI
import lcd_bus, ili9341
import task_handler
lv.init()
— Pins / constants (AZ-Touch MOD) —
_MOSI = const(23)
_MISO = const(19)
_SCK = const(18)
_LCD_CS = const(5)
_LCD_DC = const(4)
_LCD_RST= const(22)
_BL = const(15)
_WIDTH = const(240)
_HEIGHT = const(320)
— Backlight ON (explicit) —
Pin(_BL, Pin.OUT).value(1)
— SPI host = VSPI (host=2 => SCK=18, MOSI=23, MISO=19) —
spi_bus = SPI.Bus(
host=2,
mosi=_MOSI, miso=_MISO, sck=_SCK
)
— Display bus (start conservative freq) —
display_bus = lcd_bus.SPIBus(
spi_bus=spi_bus,
dc=_LCD_DC,
cs=_LCD_CS,
freq=26_000_000
)
— ILI9341 panel: MUST set color_space = RGB565 —
display = ili9341.ILI9341(
data_bus=display_bus,
display_width=_WIDTH,
display_height=_HEIGHT,
reset_pin=_LCD_RST,
reset_state=ili9341.STATE_LOW,
color_space=lv.COLOR_FORMAT.RGB565, # REQUIRED
# Try these defaults first; adjust below if colors are wrong:
color_byte_order=ili9341.BYTE_ORDER_RGB,
rgb565_byte_swap=False
)
display.set_power(1)
display.init(1) # if white/blank, try display.init(2)
display.set_rotation(0)
Build UI on the active screen (DO NOT screen_load the same screen)
scr = lv.screen_active()
lbl = lv.label(scr); lbl.set_text(“HELLO AZ-TOUCH MOD”); lbl.align(lv.ALIGN.CENTER, 0, -30)
slider = lv.slider(scr); slider.set_size(200, 20); slider.center()
Some builds need the task handler running to flush
th = task_handler.TaskHandler()
print(“Screen built”)