hi!
I’m actually making a console using cyberpi, but the display things are very slow :/, does someone know a better thing? ( i know there is lvgl library on it but this is not what i need i think)
Are there better display commands for CyberPi?
I haven’t done much of the MicroPython with CyberPi. I could try… but I doubt I can do any better than you.
I do not, the refresh rate might be low. And it has a 240 MHz Processer… So I do not think it will be possible. I also have never experimented with a CyberPi, so there you go bud
@Idaill @Rosco does have a good point, the problem might actually be with how slow the CyberPi’s processor is, not with the library you are using.
Actually, it might be surprising but, actually the cyberpi can refresh really fast, here’s all the result of refresh
Using display cyberpi :
0.00 … s to refresh the screen that showing 128x128 pixels image
0.1 ~ 0.2 s to put data into a matrice
(Where it’s really weird, it take less time to render than to put data in matrices)
And the if you use turtle, the problem is that it refresh 24/7, so turle is made so it takes time to move the turtle to lag less, but… that’s mean it takes 1 to 2 minutes to render an 128x128 pixels image.
So the cyberpi is not that slow to render but only have bad modules to play with cyberpi display stuff
Also the matrice that im talking about is 16x16 matrices only it’s using a 256 colors list
So you are using the turtle
library to render on the screen right now?
I guess I don’t completely understand your project. 0.2 seconds in slow, but 1–2 minutes is a lot worse!
0.2 to show a 1616 pixels matrice but 1 to 2 minutes using turtle to show a 128128 pixels images because of turtle wait(0.01) thing (yes it does have this)
I haven’t done much with my CyberPi display in Python, but I would suggest trying to find a different library to use besides turtle
(e.g., framebuf
or one similar to turtle
).
[ NEWS !! ]
So yes, i can use lvgl librairy
import lvgl as lv
to make things faster !
But before, you need to know that : You can’t really change images size without changing the image size ex: image of 2 by 2 pixels [0x…, 0x…, 0x…, 0x…] , if you want to change it to 3, you need to make a 3*3 list (so 9 things length list)
Hi Idaill
Could you please share more about your experience? Your setup, mb a small MVP.
I’m using the latest mblock desktop Python editor app and running into a couple of issues.
- mblock uses Python 3.6 with outdated pip, which does not allow installing LVGL out of the box.
- Yet LVGL works in upload mode, but it seems like it’s an older version (something under 8?). Their main example with the button works, but anything beyond this example struggles to execute (different import issues).
import lvgl as lv lv.init() scr = lv.obj() btn = lv.btn(scr) btn.align(lv.scr_act(), lv.ALIGN.CENTER, 0, 0) label = lv.label(btn) label.set_text("Button") lv.scr_load(scr)
Hi ! Yes, it’s the 7 version . Also you can find everything in the Discord that I created https://discord.gg/Xps8zuwE (yes sorry I’m making a promotion at the same time, but you can find everything you’re looking for in here)
Going to leave this here in case someone is researching as well.
import lvgl as lv
import cyberpi
import gc
gc.collect()
# LVGL7
"""Initiate LVGL object as CyberPI User Window"""
scr = cyberpi.display.get_user_window() # same as lv.obj() for screen
"""
lv.ALIGN methods:
IN_TOP_LEFT IN_TOP_MID IN_TOP_RIGHT
IN_LEFT_MID CENTER IN_RIGHT_MID
IN_BOTTOM_LEFT IN_BOTTOM_MID IN_BOTTOM_RIGHT
OUT_BOTTOM_LEFT OUT_BOTTOM_MID OUT_BOTTOM_RIGHT
OUT_LEFT_TOP OUT_LEFT_MID OUT_LEFT_BOTTOM
OUT_RIGHT_TOP OUT_RIGHT_MID OUT_RIGHT_BOTTOM
OUT_TOP_LEFT OUT_TOP_MID OUT_TOP_RIGHT
"""
"""BEWARE! Rectangle crashed my CyberPi the way I had to do a re-flash of the firmware"""
"""Create rectangle style"""
# r_style = lv.style_t(lv.style_plain)
# r_style.body.main_color = lv.color_make(255, 0, 0) # Red
# r_style.body.grad_color = lv.color_make(155, 0, 0) # Gradient other color is red too
# r_style.body.radius = 20 # Radius
# r_style.body.opa = lv.OPA.COVER # No transparency
# r_style.body.border.width = 0 # No border
"""Create a rectangle"""
# rect = lv.obj(cyberpi.display.get_user_window())
# rect.set_size(100, 100) # Size 100x100 pixels
# rect.align(None, lv.ALIGN.CENTER, 0, 0) #Parent is None (so it's main)
"""Apply style to rectangle"""
# rect.set_style(0, r_style)
"""Create label style"""
# style = lv.style_t()
# lv.style_copy(style, lv.style_plain)
style = lv.style_t(lv.style_plain) # same as above. Choose what better fits your style
color = lv.color_t({'ch': {'red' : 0xff}}) # Red
color_2 = lv.color_make(0, 255, 0) # Green
color_3 = lv.color_hex(0xffffff) # White
style.text.color = color_2
style.text.font = lv.font_roboto_12
style.text.letter_space = 1
style.text.line_space = 10
"""Create a button and asign a label"""
btn = lv.btn(scr)
btn.set_size(100, 20)
# btn.set_pos(20, 30)
btn.align(scr, lv.ALIGN.CENTER, 0, 10)
label = lv.label(btn)
label.set_text("Heroes on fire")
"""Apply style to label"""
label.set_style(0, style)
# lv.scr_load(scr) # Doesn't look like I need to load it. Some LVGL magic when the screen is instantiated as CyberPI User Window
"""Button generator class, reuses style from above"""
class SymbolButton(lv.btn):
def __init__(self, parent, symbol, text):
super().__init__(parent)
self.symbol = lv.label(self)
self.symbol.set_text(symbol)
self.symbol.set_style(0, style)
self.label = lv.label(self)
self.label.set_text(text)
btn1 = SymbolButton(scr, lv.SYMBOL.PLAY, "Play")
btn1.set_size(55, 50)
btn1.align(None, lv.ALIGN.IN_TOP_LEFT, 4, 2)
btn2 = SymbolButton(scr, lv.SYMBOL.PAUSE, "Pause")
btn2.set_size(55, 50)
btn2.align(btn1, lv.ALIGN.OUT_RIGHT_TOP, 10, 0)
slider = lv.slider(scr)
slider.set_width(100)
slider.align(None, lv.ALIGN.IN_BOTTOM_MID, 0, 0)
slider.set_range(0, 100)
slider.set_value(50, True) # False - renders at set value immediately
"""Rendering img"""
# Pixel format: Fix 0xFF: 8 bit, Red: 8 bit, Green: 8 bit, Blue: 8 bit
# img_data = bytes([0xff, 0xff, 0xff, ...]) # you'll need to put here an actual byte array of the img.
# img = lv.img(scr)
# img.align(scr, lv.ALIGN.CENTER, 0, 0)
# img_dsc = lv.img_dsc_t(
# {
# "header": {"always_zero": 0, "w": 100, "h": 75, "cf": lv.img.CF.TRUE_COLOR},
# "data_size": len(img_data),
# "data": img_data,
# }
# )
# img.set_src(img_dsc)
wait… how the rectangle crashed your CyberPi ? It’s not suppose to happen lol, i don’t have that problem
Frankly, no idea, cause it looks no different from any other object. Mb the whole script is too heavy for cyberpi. App locked on load with no response, no way to go back to the cyberos menu even after hard restart.
I found the documentation on LVGL micropython is an absolute trash in addition to the fact that they deleted the half of the recourses for version 7, so I ditched the idea of using it, at least for now.
I didn’t find fascinating to dig through it in REPL manually.
🧨 Common Causes of Reboot Loops on CyberPi with LVGL
Cause | Description |
---|---|
![]() |
Forgetting to clean() the screen before redrawing new widgets |
![]() |
Creating too many widgets without deleting or unloading |
![]() |
Misuse of lv.obj() or corrupted style references |
![]() |
Frequent updates or creating widgets in the main loop |
![]() |
Looping too tightly without delays |
![]() |
Repeated fast input can trigger recursive calls |