Skip to content

Problem getting ILI9486 driver to work. #306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
morrisis opened this issue Mar 1, 2025 · 1 comment
Open

Problem getting ILI9486 driver to work. #306

morrisis opened this issue Mar 1, 2025 · 1 comment

Comments

@morrisis
Copy link

morrisis commented Mar 1, 2025

Hi - and thanks in advance for any help you can give.

I have an RPI touch display with ILI9486 TFT and XPT2046 Touch screen. When programmed with the Arduino IDE in C++ and TFT_eSPI, both the display and the Touch screen work fine. I am using an esp32 WROVER-B

I have pulled and compiled lvgl_micropython this morning (2024/13/01) using the following:

python3 make.py esp32 BOARD=ESP32_GENERIC BOARD_VARIANT=SPIRAM DISPLAY=ili9486 INDEV=xpt2046

and it compiled just fine.

And it Flashes and gives the REPL prompt just fine.

~/.espressif/python_env/idf5.2_py3.11_env/bin/python -m esptool --chip esp32 -p /dev/ttyUSB0 -b 460800 --before default_reset --after hard_reset write_flash --flash_mode dio --flash_size 4MB --flash_freq 40m --erase-all 0x0 ~/src/lvgl_micropython/build/lvgl_micropy_ESP32_GENERIC-SPIRAM-4.bin

However I cannot get anything out of the display using the sample code and don't know how to get it to do something apart from power on (white screen).

This is the content of the User_setup.h from the TFT_eSPI file used for the Arduino Code:

egrep -e '^[^/]' ./libraries/TFT_eSPI/User_Setup.h 
#define USER_SETUP_INFO "User_Setup"
#define RPI_ILI9486_DRIVER // 20MHz maximum SPI
#define TOUCH_CS PIN_D2     // Chip select pin (T_CS) of touch screen
#define TFT_MISO 19
#define TFT_MOSI 23
#define TFT_SCLK 18
#define TFT_CS   15  // Chip select control pin
#define TFT_DC    2  // Data Command control pin
#define TFT_RST   4  // Reset pin (could connect to RST pin)
                        // Use an Arduino pin for initial testing as connecting to processor reset
                        // may not work (pulse too short at power up?)
#define LOAD_GLCD   // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
#define LOAD_FONT2  // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
#define LOAD_FONT4  // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
#define LOAD_FONT6  // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
#define LOAD_FONT7  // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:-.
#define LOAD_FONT8  // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
#define LOAD_GFXFF  // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts
#define SMOOTH_FONT
#define SPI_FREQUENCY  20000000
#define SPI_READ_FREQUENCY  20000000
#define SPI_TOUCH_FREQUENCY  2500000

And the content of the .py I am trying to run at the REPL prompt:

import lcd_bus
from micropython import const
import machine


 # display settings
_WIDTH = const(480)
_HEIGHT = const(320)
_BL = None #const(1)
_RST = const(4)
_DC = const(2)

_MOSI = const(23)
_MISO = const(19)
_SCK = const(18)
_HOST = const(1)  # SPI2

_LCD_CS = const(15)
_LCD_FREQ = const(20000000)

_TOUCH_CS = const(21)
_TOUCH_FREQ = const(2500000)

spi_bus = machine.SPI.Bus(
    host=_HOST,
    mosi=_MOSI,
    miso=_MISO,
    sck=_SCK
)

display_bus = lcd_bus.SPIBus(
    spi_bus=spi_bus,
    freq=_LCD_FREQ,
    dc=_DC,
    cs=_LCD_CS,
)

 # we are going to let the display driver sort out the best freame buffer size and where to allocate it to.
 # fb1 = display_bus.allocate_framebuffer(_BUFFER_SIZE, lcd_bus.MEMORY_INTERNAL | lcd_bus.MEMORY_DMA)
 # fb2 = display_bus.allocate_framebuffer(_BUFFER_SIZE, lcd_bus.MEMORY_INTERNAL | lcd_bus.MEMORY_DMA)
_BUFFER_SIZE = const(30720)
 # fb1 = display_bus.allocate_framebuffer(_BUFFER_SIZE, lcd_bus.MEMORY_INTERNAL | lcd_bus.MEMORY_DMA)
 # fb2 = display_bus.allocate_framebuffer(_BUFFER_SIZE, lcd_bus.MEMORY_INTERNAL | lcd_bus.MEMORY_DMA)

import ili9486  # NOQA
import lvgl as lv  # NOQA

print('start')
display = ili9486.ILI9486(
    data_bus=display_bus,
    display_width=_WIDTH,
    display_height=_HEIGHT,
    #backlight_pin=_BL,
    reset_pin=_RST,
    reset_state=ili9486.STATE_LOW,
    color_space=lv.COLOR_FORMAT.RGB565,
    color_byte_order=ili9486.BYTE_ORDER_RGB,
    rgb565_byte_swap=True,
    #power_on=1,
 #     frame_buffer1=fb1,
 #     frame_buffer2=fb2,
)
print('display set')

import task_handler  # NOQA
import xpt2046  # NOQA

display.set_power(True)
print('display power')
display.init()
print('display init')
display.set_backlight(100)
print('display backlight')

touch_dev = machine.SPI.Device(
    spi_bus=spi_bus,
    freq=_TOUCH_FREQ,
    cs=_TOUCH_CS
)

indev = xpt2046.XPT2046(touch_dev)

th = task_handler.TaskHandler()

scrn = lv.screen_active()
scrn.set_style_bg_color(lv.color_hex(0x444444), 0)

slider = lv.slider(scrn)
slider.set_size(300, 50)
slider.center()

label = lv.label(scrn)
label.set_text('HELLO WORLD!')
label.align(lv.ALIGN.CENTER, -150, -150)
print('end')
 #indev.calibrate()

The program runs cleanly with no errors but seems to do nothing except when I use the indev.calibrate which produces no display output but accepts touch inputs.

Frankly, apart from having read numerous discussions on similar issues on other boards, I don't know how to try to fix this. I have tried different combinations of options but don't know which is correct, and none of them have seemingly worked. There is no change at all in the display after it has powered on. No flicker or anything.

The touch screen works fine and (without UI prompts) I can click the screen and input is taken when I use indev.calibrate.

I believe I have the same values for the LVGL code as I do for the C++ code. I am hoping someone can tell me what I am missing.

Thanks again,

Moz

@kdschlosser
Copy link
Collaborator

isn't RPI Raspberry Pi?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants