2.6. Start with the LVGL GUI Simulation Project

The LVGL GUI Simulation Project provides an experimental environment for co-simulation of PikaPython and LVGL.

The GUI simulation can be performed on a PC using Visual Studio.

2.6.1. Get the project

http://pikascript.com/

Select lvgl-vs-simu, a Visual Studio simulation project, from the Project Builder on the official PikaPython website.

This project is branched from the official LVGL Visual Studio simulation project.

_images/image-20220619174705166.png

Click Generate Project and wait about 1 minute.

_images/image-20220619174908845.png

Unzip the project and open LVGL.Simulator.sln

_images/image-20220619175250783.png

Start compiling and running directly

_images/image-20220619175332172.png

You can see that the lvgl emulator has been successfully started

_images/image-20220619175456110.png

2.6.2. Programming with Python

The Python file for running the project is in LVGL.Simulator/pikascript/main.py, and it is recommended to edit the Python file with VSCode.

_images/image-20220619175630362.png

The code in main.py is shown below, and the project will run this main.py when it starts

# main.py
import pika_lvgl as lv
import PikaStdLib
mem = PikaStdLib.MemChecker()

# Create an Arc
arc = lv.arc(lv.scr_act())
arc.set_end_angle(200)
arc.set_size(150, 150)
arc.center()

print('mem used max: %0.2f kB' % (mem.getMax()))
print('mem used now: %0.2f kB' % (mem.getNow()))

More sample code

You can see more sample code in the /pikascript/examples/lvgl folder.

_images/image-20220619175945030.png

For example, you can copy lv_callback1.py into main.py.

# lv_callback1.py
import pika_lvgl as lv
import PikaStdLib
mem = PikaStdLib.MemChecker()


def event_cb_1(evt):
    print('in evt1')
    print('mem used now: %0.2f kB' % (mem.getNow()))


def event_cb_2(evt):
    print('in evt2')
    print('mem used now: %0.2f kB' % (mem.getNow()))


btn1 = lv.btn(lv.scr_act())
btn1.align(lv.ALIGN.TOP_MID, 0, 10)
btn2 = lv.btn(lv.scr_act())
btn2.align(lv.ALIGN.TOP_MID, 0, 50)
btn1.add_event_cb(event_cb_1, lv.EVENT.CLICKED, 0)
btn2.add_event_cb(event_cb_2, lv.EVENT.CLICKED, 0)

print('mem used max: %0.2f kB' % (mem.getMax()))
print('mem used now: %0.2f kB' % (mem.getNow()))

After replacing main.py, run PikaPython’s pre-compiler

_images/image-20220619180151300.png

and then start running

_images/image-20220619180208847.png

In this example you can click the button and then view the output.

_images/image-20220619180255030.png

2.6.3. Frequently Asked Questions

If you are prompted for missing functions, you need to manually add the files to be compiled

Right-click on pikascript/pikascript-api and pikascript/pikascript-lib and click “Include in project”, then recompile.

_images/image-20220619180512784.png