MicroPython examples for V7?

Hi Amir,
I wanted to try the ili9341 version of demo_printer but I cannot rebuild lv_micropython any more:

                 from /opt/ucc/micros/esp32/esp-idf-micropython/components/bt/host/nimble/nimble/nimble/host/src/ble_hs_periodic_sync.c:23:
/opt/ucc/micros/esp32/esp-idf-micropython/components/bt/host/nimble/port/include/esp_nimble_cfg.h:13:49: error: 'MYNEWT_VAL_BLE_MAX_PERIODIC_SYNCS' undeclared here (not in a function); did you mean 'MYNEWT_VAL_BLE_MAX_CONNECTIONS'?
 #define MYNEWT_VAL(x)                           MYNEWT_VAL_ ## x ```
                                                 ^~~~~~~~~~~

Sorry, forget my compilation problems. It was probably a wrong espidf configuration

@kisvegabor Are you using the latest lv_micropython? It’s needed because I added display_driver_utils as a frozen module there.
You can also try to add these 2 lines at before any import in demo_printer.py:

import sys
sys.path.append('')

This is not needed as these modules are frozen, just add the lines above.

@uraich I’m not sure I follow if there is a problem with dynamic font loading or not.
Were you able to run Dynamic_loading_font_example.py?

Please let us know the current status and where you still have trouble.

Thanks, I got one step closer. After updating lv_micropython MICROPYPATH="" worked as well. (it was a few weeks old). Now ulogging is missing.
I’ve tired to install upip but

$ pip install micropython-upip
Defaulting to user installation because normal site-packages is not writeable
Collecting micropython-upip
  Using cached micropython-upip-1.2.6.tar.gz (4.3 kB)
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3.6 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-vv5hi0ap/micropython-upip/setup.py'"'"'; __file__='"'"'/tmp/pip-install-vv5hi0ap/micropython-upip/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-8s7737u2
         cwd: /tmp/pip-install-vv5hi0ap/micropython-upip/
    Complete output (5 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/usr/lib/python3.6/tokenize.py", line 452, in open
        buffer = _builtin_open(filename, 'rb')
    FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-install-vv5hi0ap/micropython-upip/setup.py'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
WARNING: You are using pip version 20.1.1; however, version 21.0.1 is available.
You should consider upgrading via the '/usr/bin/python3.6 -m pip install --upgrade pip' command.

I’ve also tried:

$ ./micropython-dev -m upip install logging
Installing to: /home/kisvegabor/.micropython/lib/
Warning: micropython.org SSL certificate is not validated
Installing logging 0.3 from https://micropython.org/pi/logging/logging-0.3.tar.gz

It says it installed successfully, but the ulogging module still can’t be found.

@kisvegabor Are you using latest version of lv_mpy_examples repo? @uraich changed it such that it doesn’t rely on ulogging.

I don’t think you need to install anything with upip for running this.

I’ve used the lv_examples repo. I thought the version there is the same as in @uraich’s repo.

Anyway, with lv_mpy_examples it works! I saw only a few visual glitches on the animations.

The printer demo is quite complex with several widget types, a custom theme, animations, a lot of objects, and intensive object creation/deletion.

It’s huge to see the MicroPython binding handles all these. :clap::clap::clap:

Great!
Could you let us know what were the visual glitches you identified in animations?

The most visible glitch is the header animation on screnchange:
Screencast 2021-03-03 08:49:21.mp4.zip (104.5 KB)

And on the USB screen, one of the dropdowns is misaligned.

I use lv_mpy_examples as my playground before preparing a pull request.
Thanks for the report on the glitches.
In fact I saw the re-alignment but then somehow it miraculously disappeared. I have been messing around with lv_conf.h and with espidf, playing with the new build system of micropython. Like this I managed to put my system into a state where nothing worked any longer. Now I am back to normal and I also see the misalignment. Like this it should be much easier to track it down.

Hi Amir and Gabor,
Can you please check if the mis-alignment glitch is gone?
Thanks

I had challenges with dynamic font loading. When running the Dynamic_loading_font_example.py I get an error:
KeyError: ‘type’ object isn’t subscriptable
I see that in fs_driver a dictionary is attached to the lv_fs_file_t structure in the open call, which contains the file descriptor. Unfortunately this dictionary is not correctly recuperated by the other calls. Instead of the dictionary itself, its type is recuperated resulting in the error.
My solution was to re-write fs_driver.py as a class and keep the file descriptor as an instance variable. This makes the code substantially shorter and also clearer (I believe).
image
Uploaded to lv_mpy_examples
Please let me know what you think of it.

Something probably changed because it used to work with older versions.
Actually it’s not clear to me why the callbacks receive void * instead of lv_fs_file_t *, which could spare all these horrible casts.

@kisvegabor, @embeddedt Do you know if there is a reason the FS callbacks receive void * file_p instead of lv_fs_file_t * file_p? I would very much like to change that in lv_fs.h such that casts could be eliminated from Micropython.

@uraich -

  • Best thing would be to fix lv_fs.h on LVGL and get rid of all these casts on Microython.
    I don’t mind converting fs_driver.py to a class but I think this change should be applied in lv_micropython/lib. I don’t see a reason to keep a separate implementation of fs driver in the demo. We can also freeze it in lv_micropython/lib such that it is always available same as display_driver_utils.py.
  • The mis-alignment glitch seems to be fixed!

Ok, I will wait for the fix in lv_fs.h. When I saw the program running I remembered that I had tried it several months ago, and, you are right, then it worked fine.
Actually I only did the conversion to a class only to check that I had correctly understood your mechanism to save the file descriptor.
I will try to dynamically load the fonts in the demo_printer program with the class fs_driver waiting for the fix. There is hardly any change to switch back later anyhow.
Good that the mis-alignment problem is gone.
During the next one or two weeks however I will have little time to work on this. My house got burglarized and it have to get things in order there first.
Hmmm, the changes for dynamic font loading were so few that I could easily implement them. I have most of the montserrat fonts in the font directory even though only 2 are used by demo_printer. Now the program should “just run”.
The ili9341 version is also almost ready but not tested on the esp32 yet.

Hi,I run the ‘demo_printer’ code, everything is well excpet the images. Who can tell me how to convert ‘XXX_argb8888.bin’ to ‘XXX_rgb565.bin’

It must be XXX_argb8888.bin’ to ‘XXX_argb565.bin.
You find the conversion programs in https://github.com/uraich/lv_mpy_examples
under image_conversions.
Just run make to create the executables.
Then use:
argb8888_to_argb565 xxxx_argb8888.bin image_width image_height
You may also try
argb8888_to_png xxxx_argb8888.bin image_width image_height
to create, you guessed it, the png file.
showImg.py argb8888.bin image_width image_height will display the image.
Please tell me if this works for you.

Thank you for your reply. I configure LTDC as RGB565 format. use argb8888,I get this:

I had this when the color format was wrongly configured in lv.conf.h. Are you sure you have defined 16 bit color format there?

I use ‘#define LV_COLOR_DEPTH 16’ to make micropython firmware.

In image_conversions, I get an error when I run ‘make’.

cc -g -Wall    rgb565_to_argb8888.c  -lpng -o rgb565_to_argb8888
/usr/bin/ld: cannot find -lpng
collect2: error: ld returned 1 exit status
<builtin>: recipe for target 'rgb565_to_argb8888' failed
make: *** [rgb565_to_argb8888] Error 1

You are missing libpng on your system.
2 possible solutions:
If you are on Ubuntu use
sudo apt install libpng-dev
If you only want the converter to argb565, then you can remove

  • LDLIBS = -lpng
  • and all references to argb8888_to_png from the Makefile and re-build

Great,now I converter images to argb565, and modified image reading code in demo_printer.py:

sdl_filename = self.images_lib + filename + "_argb565.bin"

I got this: