2.7. Start with the LVGL GUI Simulation Project

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

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

2.7.1. Get the project

http://pikascript.com/

Select lvgl-vs-simu, a Visual Studio simulation project, from the Project Builder on the official PikaScript 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.7.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

  1. # main.py
  2. import pika_lvgl as lv
  3. import PikaStdLib
  4. mem = PikaStdLib.MemChecker()
  5. # Create an Arc
  6. arc = lv.arc(lv.scr_act())
  7. arc.set_end_angle(200)
  8. arc.set_size(150, 150)
  9. arc.center()
  10. print('mem used max: %0.2f kB' % (mem.getMax()))
  11. 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.

  1. # lv_callback1.py
  2. import pika_lvgl as lv
  3. import PikaStdLib
  4. mem = PikaStdLib.MemChecker()
  5. def event_cb_1(evt):
  6. print('in evt1')
  7. print('mem used now: %0.2f kB' % (mem.getNow()))
  8. def event_cb_2(evt):
  9. print('in evt2')
  10. print('mem used now: %0.2f kB' % (mem.getNow()))
  11. btn1 = lv.btn(lv.scr_act())
  12. btn1.align(lv.ALIGN.TOP_MID, 0, 10)
  13. btn2 = lv.btn(lv.scr_act())
  14. btn2.align(lv.ALIGN.TOP_MID, 0, 50)
  15. btn1.add_event_cb(event_cb_1, lv.EVENT.CLICKED, 0)
  16. btn2.add_event_cb(event_cb_2, lv.EVENT.CLICKED, 0)
  17. print('mem used max: %0.2f kB' % (mem.getMax()))
  18. print('mem used now: %0.2f kB' % (mem.getNow()))

After replacing main.py, run PikaScript’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.7.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