Skip to content
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

Abnormal color display on LCD with RP pico #322

Closed
yusuhua opened this issue Jan 27, 2024 · 6 comments
Closed

Abnormal color display on LCD with RP pico #322

yusuhua opened this issue Jan 27, 2024 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@yusuhua
Copy link

yusuhua commented Jan 27, 2024

Recently, I used the latest master to compile the firmware of RP pico. When I ran examples/generic-st77xx-with-xpt2046.py, I found an error. I changed line 416 of st77xx.py from lv.disp_create to lv.display_create and it ran successfully, but It is found that the color display is abnormal, as shown in the figure:
WechatIMG86
The white background turned to light green, and the buttons turned to yellow.
After adding the bgr=True parameter, the button is blue, but the white background is still light green, and the text looks blurry.
WechatIMG87
The device I'm using is: https://www.waveshare.com/Pico-ResTouch-LCD-2.8.htm

@PGNetHun
Copy link
Collaborator

Hello!
That's a known issue: some displays require that the 16 bit RGB565 pixel data bytes are swapped.
There is a function in LVGL that swaps the bytes: lv.draw_sw_rgb565_swap

I have fixed this issue in PR: lvgl/lv_micropython#73
It is merged to main, so please pull repo, build, and test again.
Set bgr parameter to False to swap RGB565 bytes.

@PGNetHun PGNetHun self-assigned this Jan 27, 2024
@PGNetHun PGNetHun added the bug Something isn't working label Jan 27, 2024
@yusuhua
Copy link
Author

yusuhua commented Jan 30, 2024

I pulled the repo again and rebuilt a firmware, but found an error when running Thonny:
`>>> %Run -c $EDITOR_CONTENT

MPY: soft reboot
PROBLEM IN THONNY'S BACK-END: Exception while handling 'Run' (thonny.plugins.micropython.mp_back.ProtocolError: Unexpected read during raw paste).
See Thonny's backend.log for more info.
You may need to press "Stop/Restart" or hard-reset your MicroPython device and try again.

Process ended with exit code 1.
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
�KeyboardInterrupt:

MPY: soft reboot
MicroPython v1.20.0-703-gcc50c7aa5 on 2024-01-30; Raspberry Pi Pico with RP2040
Type "help()" for more information.

`

The display screen shows snowflakes:
WechatIMG88

Here is the Thonny's backend.log
backend.log

@PGNetHun
Copy link
Collaborator

Please send your MicroPython code (I'm interested in display creation, and whether LVGL loop is initiated, and screenshot of serial port output (console output) when you restart. Attach these to the new comment.
So I can test the same code (but different display).

@yusuhua
Copy link
Author

yusuhua commented Feb 2, 2024

Sure, my code is generic-st77xx-with-xpt2046.py in your examples. I only changed btn.add_event(lambda event: print('Button clicked!'),lv.EVENT.CLICKED,None) in the 35th line to btn.add_event_cb(lambda event: print('Button clicked!'),lv.EVENT.CLICKED,None).
The other driver files are from:
st77xx.py
xpt2046.py
lv_utils.py

@PGNetHun
Copy link
Collaborator

PGNetHun commented Feb 4, 2024

Hello @yusuhua ,
There was a bug in st77xx.py file, that variables w and h were used before set.
That is fixed in lv_binding PR 326, and I have tested it on Raspberry Pi Pico W + ILI9341 display, and it works.
Could you please pull repo and test again?

Note, that Pico has not so much memory, so increase factor parameter (split screen into smaller pieces for partial rendering), and disable double buffering to save RAM.

This is how I connected ILI9341 display to Pico (without touch part):
cpyPico_spi_ILI9341 touch_bbxx

Code:

import lvgl as lv

try:
    if not lv.is_initialized():
        print("Init LVGL")
        lv.init()
        print("Init LVGL - DONE")

    import lv_utils
    if lv_utils.event_loop.is_running():
        print("Deinit lv_utils.event_loop")
        lv_utils.event_loop.current_instance.deinit()
        print("Deinit lv_utils.event_loop - DONE")

    print("Create SPI")
    import machine
    spi = machine.SPI(
        0,
        baudrate=24_000_000,
        sck=machine.Pin(6, machine.Pin.OUT),
        mosi=machine.Pin(7, machine.Pin.OUT)
    )
    print("Create SPI - DONE")

    print("Init Ili9341")
    import ili9xxx
    drv = ili9xxx.Ili9341(rot=3, spi=spi, cs=13, dc=15,
                          rst=14, factor=8, doublebuffer=False)
    print("Init Ili9341 - DONE")

    print("Show screen")
    screen = lv.obj()
    button = lv.button(screen)
    button.center()
    label = lv.label(button)
    label.set_text("Hello World!")
    label.center()
    lv.screen_load(screen)
    print("Show screen - DONE")

except Exception as e:
    print(e)

@yusuhua
Copy link
Author

yusuhua commented Feb 5, 2024

Great!
The display is now normal.
Thanks~!@PGNetHun

@PGNetHun PGNetHun closed this as completed Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants