This repository extends LV-MicroPython for using it on the M5Stack Core2. It adds support for the:
More examples can be found inside the examples
folder.
Drag Me Example | Buttons Example |
import gc
import lvgl as lv
from axpili9342 import ili9341
from ft6x36c import ft6x36
display = ili9341()
touch = ft6x36()
def drag_event_handler(e):
obj = e.get_target()
indev = lv.indev_get_act()
vect = lv.point_t()
indev.get_vect(vect)
x = obj.get_x() + vect.x
y = obj.get_y() + vect.y
obj.set_pos(x, y)
obj = lv.obj(lv.scr_act())
obj.set_size(150, 100)
obj.add_event_cb(drag_event_handler, lv.EVENT.PRESSING, None)
label = lv.label(obj)
label.set_text("Drag me")
label.center()
I've included a compiled MicroPython firmware (check the firmware
folder). The firmware was compiled using following versions and hashes:
b64925c56
bf62dfc784
To flash it to the board, you need to type the following:
esptool.py --chip esp32 --port /dev/ttyUSB0 erase_flash
esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 1152000 write_flash -z 0x1000 lv_micropython_m5core2_bf62dfc784_esp32_idf4_4_x.bin
More information is available in this tutorial.
If you want to compile your driver from scratch follow the next section:
Read this section if you want to include the camera support to MicroPython from scratch. To do that follow these steps:
Note 1: if you get stuck, those pages are a good help:
Note 2: Up to micropython version 1.14, the build tool for the esp32 port is Make. Starting with this PR, it is CMAKE. You can find more discussion in this micropython forum blog post
Clone the MicroPython repository:
git clone --recursive https://github.com/littlevgl/lv_micropython.git
Note: The MicroPython repo changes a lot, I've done this using the version with the hash mentioned above.
:warning: If you want to directly replace the original files with the provided in this repository, be sure that you've taken the same commit hash. MicroPython changes a lot, and you'll compiling issues if you ignore this warning.
Copy the files and folders inside the boards
folder into micropython/ports/esp32/boards
or use a symbolic link (ln -s
).
Create a m5core2
folder inside ~/esp/esp-idf/components
and copy the files and folders inside the components
inside that folder.
Compile the firmware by typing following commands:
cd micropython/ports/esp32
. $HOME/esp/esp-idf/export.sh
make USER_C_MODULES=../../../../micropython-core2/src/micropython.cmake BOARD=M5STACK_CORE2 all
Note that the folder micropython-core2
should be in the same folder level as the micropython
. Otherwise, you'll need to change the path (../../../../micropython-core2/src/
) to the micropython.cmake
file.
Deploy the firmware into the ESP32 by typing:
cd micropython/ports/esp32
esptool.py --port /dev/ttyUSB0 erase_flash
esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 1152000 write_flash -z 0x1000 build-M5STACK_CORE2/firmware.bin