{"id":15061506,"url":"https://github.com/bunnysakura/lv_micropython","last_synced_at":"2025-10-31T14:30:37.968Z","repository":{"id":256569868,"uuid":"854191890","full_name":"BunnySakura/lv_micropython","owner":"BunnySakura","description":"适用于具有16M flash的ESP32芯片的MicroPython LVGL绑定 | Micropython bindings to LVGL for Embedded devices, Unix and JavaScript | M5Stack BASIC","archived":false,"fork":false,"pushed_at":"2024-12-04T11:55:04.000Z","size":65287,"stargazers_count":3,"open_issues_count":5,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-15T04:51:14.926Z","etag":null,"topics":["esp32","gui","lvgl","lvgl-esp32","m5stack","m5stack-core","micropython","mpy"],"latest_commit_sha":null,"homepage":"https://www.333rd.net/zh/posts/tech/%E7%A7%BB%E6%A4%8Dmicropython%E7%9A%84lvgl%E7%BB%91%E5%AE%9A%E5%88%B0esp32/","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BunnySakura.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"micropython"}},"created_at":"2024-09-08T16:09:12.000Z","updated_at":"2024-12-20T02:30:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"1c33e03f-cb8b-4bc4-8a5e-f9b7d3d8a977","html_url":"https://github.com/BunnySakura/lv_micropython","commit_stats":{"total_commits":14770,"total_committers":611,"mean_commits":"24.173486088379704","dds":0.6267433987813135,"last_synced_commit":"64c6593dc1da539b91f4a39c6824e531ca86da94"},"previous_names":["bunnysakura/lv_micropython"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BunnySakura%2Flv_micropython","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BunnySakura%2Flv_micropython/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BunnySakura%2Flv_micropython/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BunnySakura%2Flv_micropython/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BunnySakura","download_url":"https://codeload.github.com/BunnySakura/lv_micropython/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239207445,"owners_count":19599963,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["esp32","gui","lvgl","lvgl-esp32","m5stack","m5stack-core","micropython","mpy"],"created_at":"2024-09-24T23:20:24.678Z","updated_at":"2025-10-31T14:30:37.920Z","avatar_url":"https://github.com/BunnySakura.png","language":"C","readme":"# Micropython + lvgl\n\n**Micropython bindings to LVGL for Embedded devices, Unix and JavaScript**\n\n[![Build lv_micropython unix port](https://github.com/lvgl/lv_micropython/actions/workflows/unix_port.yml/badge.svg)](https://github.com/lvgl/lv_micropython/actions/workflows/unix_port.yml)\n[![Build lv_micropython stm32 port](https://github.com/lvgl/lv_micropython/actions/workflows/stm32_port.yml/badge.svg)](https://github.com/lvgl/lv_micropython/actions/workflows/stm32_port.yml)\n[![esp32 port](https://github.com/lvgl/lv_micropython/actions/workflows/ports_esp32.yml/badge.svg)](https://github.com/lvgl/lv_micropython/actions/workflows/ports_esp32.yml) [![Build lv_micropython rp2 port](https://github.com/lvgl/lv_micropython/actions/workflows/rp2_port.yml/badge.svg)](https://github.com/lvgl/lv_micropython/actions/workflows/rp2_port.yml)\n[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/lvgl/lv_micropython)  \n\nTo quickly run Micropython + LVGL from your web browser you can also use the [Online Simulator](https://sim.lvgl.io/).\n\n**For information about Micropython lvgl bindings please refer to [lv_binding_micropython/README.md](https://github.com/lvgl/lv_binding_micropython/blob/master/README.md)**\n\nSee also [Micropython + LittlevGL](https://blog.lvgl.io/2019-02-20/micropython-bindings) blog post. (LittlevGL is LVGL's previous name.)  \nFor questions and discussions - please use the forum: https://forum.lvgl.io/c/micropython\n\nOriginal micropython README: https://github.com/micropython/micropython/blob/master/README.md\n\n## Relationship between `lv_micropython` and `lv_binding_micropython`\n\nOriginally, `lv_micropython` was created as an example of how to use [lv_binding_micropython](https://github.com/lvgl/lv_binding_micropython) on a Micropython fork.  \nAs such, we try to keep changes here as minimal as possible and we try to keep it in sync with Micropython upstream releases. We also try to add changes to `lv_binding_micropython` instead of to `lv_micropython`, when possible. (for example we keep all drivers in `lv_binding_micropython`, the ESP32 CMake functionality etc.)\n\nEventually it turned out that many people prefer using `lv_micropython` directly and only a few use it as a reference to support LVGL on their own Micropython fork.\nIf you are only starting with Micropython+LVGL, it's recommended that you use `lv_micropython`, while porting a Micropython fork to LVGL is for advanced users.\n\n## Build Instructions\n\nFirst step is always to clone lv_micropython and update its submodules recursively:\n\n```\ngit clone https://github.com/lvgl/lv_micropython.git\ncd lv_micropython\ngit submodule update --init --recursive lib/lv_bindings\n```\n\nNext you should build mpy-cross\n\n```\nmake -C mpy-cross\n```\n\nPort specific steps usually include updating the port's submodules with `make submodules` and running make for the port itself.\n\n### Unix (Linux) port\n\n1. `sudo apt-get install build-essential libreadline-dev libffi-dev git pkg-config libsdl2-2.0-0 libsdl2-dev python3.8 parallel`\nPython 3 is required, but you can install some other version of python3 instead of 3.8, if needed.\n2. `git clone https://github.com/lvgl/lv_micropython.git`\n3. `cd lv_micropython`\n4. `git submodule update --init --recursive lib/lv_bindings`\n5. `make -C mpy-cross`\n6. `make -C ports/unix submodules`\n7. `make -C ports/unix`\n8. `./ports/unix/micropython`\n\n## Unix (MAC OS) port\n\n1. `brew install sdl2 pkg-config`\n2. `git clone https://github.com/lvgl/lv_micropython.git`\n3. `cd lv_micropython`\n4. `git submodule update --init --recursive lib/lv_bindings`\n5. `sudo mkdir -p /usr/local/lib/`\n6. `sudo cp /opt/homebrew/Cellar/sdl2/2.24.0/lib/libSDL2.dylib /usr/local/lib/`\n7. `sudo cp -r /opt/homebrew/Cellar/sdl2/2.24.0/include /usr/local/`\n8. `sed -i '' 's/ -Werror//' ports/unix/Makefile` Remove -Werror from compiler parameters as Mac fails compilation otherwise\n9. `make -C mpy-cross`\n10. `make -C ports/unix submodules`\n11. `make -C ports/unix`\n12. `./ports/unix/micropython`\n\n### ESP32 port\n\nPlease run `esp-idf/export.sh` from your ESP-IDF installation directory as explained in the [Micropython ESP32 Getting Started documentation](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/get-started/#get-started-export)  \nESP-IDF version needs to match Micropython expected esp-idf, otherwise a warning will be displayed (and build will probably fail)\nFor more details refer to [Setting up the toolchain and ESP-IDF](https://github.com/lvgl/lv_micropython/blob/master/ports/esp32/README.md#setting-up-the-toolchain-and-esp-idf)\n\nWhen using IL9341 driver, the color depth need to be set to match ILI9341. This can be done from the command line.\nHere is the command to build ESP32 + LVGL which is compatible with ILI9341 driver:\n\n```\nmake -C mpy-cross\nmake -C ports/esp32 LV_CFLAGS=\"-DLV_COLOR_DEPTH=16\" BOARD=GENERIC_SPIRAM deploy\n```\n\nExplanation about the paramters:\n- `LV_CFLAGS` are used to override color depth, for ILI9341 compatibility.\n  - `LV_COLOR_DEPTH=16` is needed if you plan to use the ILI9341 driver.\n- `BOARD` - I use WROVER board with SPIRAM. You can choose other boards from `ports/esp32/boards/` directory.\n- `deploy` - make command will create ESP32 port of Micropython, and will try to deploy it through USB-UART bridge.\n\nFor more details please refer to [Micropython ESP32 README](https://github.com/micropython/micropython/blob/master/ports/esp32/README.md).\n\n### JavaScript port\n\nRefer to the README of the `lvgl_javascript` branch: https://github.com/lvgl/lv_micropython/tree/lvgl_javascript_v8#javascript-port\n\n### Raspberry Pi Pico port\n\nThis port uses [Micropython infrastructure for C modules](https://docs.micropython.org/en/latest/develop/cmodules.html#compiling-the-cmodule-into-micropython) and `USER_C_MODULES` must be given:\n\n1. `git clone https://github.com/lvgl/lv_micropython.git`\n2. `cd lv_micropython`\n3. `git submodule update --init --recursive lib/lv_bindings`\n4. `make -C ports/rp2 BOARD=PICO submodules`\n5. `make -j -C mpy-cross`\n6. `make -j -C ports/rp2 BOARD=PICO USER_C_MODULES=../../lib/lv_bindings/bindings.cmake`\n\n#### Troubleshooting\n\nIf you experience unstable behaviour, it is worth checking the value of *MICROPY_HW_FLASH_STORAGE_BASE* against the value of *__flash_binary_end* from the firmware.elf.map file.\nIf the storage base is lower than the binary end, parts of the firmware will be overwritten when the micropython filesystem is initialised.\n\n## Super Simple Example\n\nFirst, LVGL needs to be imported and initialized\n\n```python\nimport lvgl as lv\nlv.init()\n```\n\nThen event loop, display driver and input driver needs to be registered.\nRefer to [Porting the library](https://docs.lvgl.io/8.0/porting/index.html) for more information.\nHere is an example of registering SDL drivers on Micropython unix port:\n\n```python\n# Create an event loop and Register SDL display/mouse/keyboard drivers.\nfrom lv_utils import event_loop\n\nWIDTH = 480\nHEIGHT = 320\n\nevent_loop = event_loop()\ndisp_drv = lv.sdl_window_create(WIDTH, HEIGHT)\nmouse = lv.sdl_mouse_create()\nkeyboard = lv.sdl_keyboard_create()\nkeyboard.set_group(self.group)\n```\n\nHere is an alternative example, for registering ILI9341 drivers on Micropython ESP32 port:\n\n```python\nimport lvgl as lv\n\n# Import ILI9341 driver and initialized it\n\nfrom ili9341 import ili9341\ndisp = ili9341()\n\n# Import XPT2046 driver and initalize it\n\nfrom xpt2046 import xpt2046\ntouch = xpt2046()\n```\n\nBy default, both ILI9341 and XPT2046 are initialized on the same SPI bus with the following parameters:\n\n- ILI9341: `miso=5, mosi=18, clk=19, cs=13, dc=12, rst=4, power=14, backlight=15, spihost=esp.HSPI_HOST, mhz=40, factor=4, hybrid=True`\n- XPT2046: `cs=25, spihost=esp.HSPI_HOST, mhz=5, max_cmds=16, cal_x0 = 3783, cal_y0 = 3948, cal_x1 = 242, cal_y1 = 423, transpose = True, samples = 3`\n\nYou can change any of these parameters on ili9341/xpt2046 constructor.\nYou can also initalize them on different SPI buses if you want, by providing miso/mosi/clk parameters. Set them to -1 to use existing (initialized) spihost bus.\n\nNow you can create the GUI itself:\n\n```python\n\n# Create a screen with a button and a label\n\nscr = lv.obj()\nbtn = lv.btn(scr)\nbtn.align_to(lv.scr_act(), lv.ALIGN.CENTER, 0, 0)\nlabel = lv.label(btn)\nlabel.set_text(\"Hello World!\")\n\n# Load the screen\n\nlv.scr_load(scr)\n\n```\n\n## More information\n\nMore info about LVGL:\n- Website https://lvgl.io\n- GitHub: https://github.com/lvgl/lvgl\n- Documentation: https://docs.lvgl.io/master/get-started/bindings/micropython.html\n- Examples: https://docs.lvgl.io/master/examples.html\n- More examples: https://github.com/lvgl/lv_binding_micropython/tree/master/examples\n\nMore info about lvgl Micropython bindings:\n- https://github.com/lvgl/lv_binding_micropython/blob/master/README.md\n\nDiscussions about the Micropython binding: https://github.com/lvgl/lvgl/issues/557\n\nMore info about the unix port: https://github.com/micropython/micropython/wiki/Getting-Started#debian-ubuntu-mint-and-variants\n\nThe MicroPython project\n=======================\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/micropython/micropython/master/logo/upython-with-micro.jpg\" alt=\"MicroPython Logo\"/\u003e\n\u003c/p\u003e\n\nThis is the MicroPython project, which aims to put an implementation\nof Python 3.x on microcontrollers and small embedded systems.\nYou can find the official website at [micropython.org](http://www.micropython.org).\n\nWARNING: this project is in beta stage and is subject to changes of the\ncode-base, including project-wide name changes and API changes.\n\nMicroPython implements the entire Python 3.4 syntax (including exceptions,\n`with`, `yield from`, etc., and additionally `async`/`await` keywords from\nPython 3.5 and some select features from later versions). The following core\ndatatypes are provided: `str`(including basic Unicode support), `bytes`,\n`bytearray`, `tuple`, `list`, `dict`, `set`, `frozenset`, `array.array`,\n`collections.namedtuple`, classes and instances. Builtin modules include\n`os`, `sys`, `time`, `re`, and `struct`, etc. Select ports have support for\n`_thread` module (multithreading), `socket` and `ssl` for networking, and\n`asyncio`. Note that only a subset of Python 3 functionality is implemented\nfor the data types and modules.\n\nMicroPython can execute scripts in textual source form (.py files) or from\nprecompiled bytecode (.mpy files), in both cases either from an on-device\nfilesystem or \"frozen\" into the MicroPython executable.\n\nMicroPython also provides a set of MicroPython-specific modules to access\nhardware-specific functionality and peripherals such as GPIO, Timers, ADC,\nDAC, PWM, SPI, I2C, CAN, Bluetooth, and USB.\n\nGetting started\n---------------\n\nSee the [online documentation](https://docs.micropython.org/) for API\nreferences and information about using MicroPython and information about how\nit is implemented.\n\nWe use [GitHub Discussions](https://github.com/micropython/micropython/discussions)\nas our forum, and [Discord](https://discord.gg/RB8HZSAExQ) for chat. These\nare great places to ask questions and advice from the community or to discuss your\nMicroPython-based projects.\n\nFor bugs and feature requests, please [raise an issue](https://github.com/micropython/micropython/issues/new/choose)\nand follow the templates there.\n\nFor information about the [MicroPython pyboard](https://store.micropython.org/pyb-features),\nthe officially supported board from the\n[original Kickstarter campaign](https://www.kickstarter.com/projects/214379695/micro-python-python-for-microcontrollers),\nsee the [schematics and pinouts](http://github.com/micropython/pyboard) and\n[documentation](https://docs.micropython.org/en/latest/pyboard/quickref.html).\n\nContributing\n------------\n\nMicroPython is an open-source project and welcomes contributions. To be\nproductive, please be sure to follow the\n[Contributors' Guidelines](https://github.com/micropython/micropython/wiki/ContributorGuidelines)\nand the [Code Conventions](https://github.com/micropython/micropython/blob/master/CODECONVENTIONS.md).\nNote that MicroPython is licenced under the MIT license, and all contributions\nshould follow this license.\n\nAbout this repository\n---------------------\n\nThis repository contains the following components:\n- [py/](py/) -- the core Python implementation, including compiler, runtime, and\n  core library.\n- [mpy-cross/](mpy-cross/) -- the MicroPython cross-compiler which is used to turn scripts\n  into precompiled bytecode.\n- [ports/](ports/) -- platform-specific code for the various ports and architectures that MicroPython runs on.\n- [lib/](lib/) -- submodules for external dependencies.\n- [tests/](tests/) -- test framework and test scripts.\n- [docs/](docs/) -- user documentation in Sphinx reStructuredText format. This is used to generate the [online documentation](http://docs.micropython.org).\n- [extmod/](extmod/) -- additional (non-core) modules implemented in C.\n- [tools/](tools/) -- various tools, including the pyboard.py module.\n- [examples/](examples/) -- a few example Python scripts.\n\n\"make\" is used to build the components, or \"gmake\" on BSD-based systems.\nYou will also need bash, gcc, and Python 3.3+ available as the command `python3`\n(if your system only has Python 2.7 then invoke make with the additional option\n`PYTHON=python2`). Some ports (rp2 and esp32) additionally use CMake.\n\nSupported platforms \u0026 architectures\n-----------------------------------\n\nMicroPython runs on a wide range of microcontrollers, as well as on Unix-like\n(including Linux, BSD, macOS, WSL) and Windows systems.\n\nMicrocontroller targets can be as small as 256kiB flash + 16kiB RAM, although\ndevices with at least 512kiB flash + 128kiB RAM allow a much more\nfull-featured experience.\n\nThe [Unix](ports/unix) and [Windows](ports/windows) ports allow both\ndevelopment and testing of MicroPython itself, as well as providing\nlightweight alternative to CPython on these platforms (in particular on\nembedded Linux systems).\n\nThe [\"minimal\"](ports/minimal) port provides an example of a very basic\nMicroPython port and can be compiled as both a standalone Linux binary as\nwell as for ARM Cortex M4. Start with this if you want to port MicroPython to\nanother microcontroller. Additionally the [\"bare-arm\"](ports/bare-arm) port\nis an example of the absolute minimum configuration, and is used to keep\ntrack of the code size of the core runtime and VM.\n\nIn addition, the following ports are provided in this repository:\n - [cc3200](ports/cc3200) -- Texas Instruments CC3200 (including PyCom WiPy).\n - [esp32](ports/esp32) -- Espressif ESP32 SoC (including ESP32S2, ESP32S3, ESP32C3).\n - [esp8266](ports/esp8266) -- Espressif ESP8266 SoC.\n - [mimxrt](ports/mimxrt) -- NXP m.iMX RT (including Teensy 4.x).\n - [nrf](ports/nrf) -- Nordic Semiconductor nRF51 and nRF52.\n - [pic16bit](ports/pic16bit) -- Microchip PIC 16-bit.\n - [powerpc](ports/powerpc) -- IBM PowerPC (including Microwatt)\n - [qemu-arm](ports/qemu-arm) -- QEMU-based emulated target, for testing)\n - [renesas-ra](ports/renesas-ra) -- Renesas RA family.\n - [rp2](ports/rp2) -- Raspberry Pi RP2040 (including Pico and Pico W).\n - [samd](ports/samd) -- Microchip (formerly Atmel) SAMD21 and SAMD51.\n - [stm32](ports/stm32) -- STMicroelectronics STM32 family (including F0, F4, F7, G0, G4, H7, L0, L4, WB)\n - [teensy](ports/teensy) -- Teensy 3.x.\n - [webassembly](ports/webassembly) -- Emscripten port targeting browsers and NodeJS.\n - [zephyr](ports/zephyr) -- Zephyr RTOS.\n\nThe MicroPython cross-compiler, mpy-cross\n-----------------------------------------\n\nMost ports require the [MicroPython cross-compiler](mpy-cross) to be built\nfirst.  This program, called mpy-cross, is used to pre-compile Python scripts\nto .mpy files which can then be included (frozen) into the\nfirmware/executable for a port.  To build mpy-cross use:\n\n    $ cd mpy-cross\n    $ make\n\nExternal dependencies\n---------------------\n\nThe core MicroPython VM and runtime has no external dependencies, but a given\nport might depend on third-party drivers or vendor HALs. This repository\nincludes [several submodules](lib/) linking to these external dependencies.\nBefore compiling a given port, use\n\n    $ cd ports/name\n    $ make submodules\n\nto ensure that all required submodules are initialised.\n","funding_links":["https://github.com/sponsors/micropython"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbunnysakura%2Flv_micropython","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbunnysakura%2Flv_micropython","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbunnysakura%2Flv_micropython/lists"}