2.9. ARM-2D based GUI simulation project

2.9.1. Preface

good news! The Arm2D module and simulation project of pikascript are preliminarily sorted out! pikaScript, ARM-2D, rt-thread work together, unlock new poses for python to play Arm2D! No hardware is needed, and it can be simulated directly, which is very convenient.

It is also very simple to deploy and run this simulation project on your own computer, just follow the steps below~

2.9.2. Get the simulation project

First enter the code repository of PikaScript

https://github.com/pikastech/pikascript (requires scientific Internet access)

_images/139675132-739ec77b-db22-4ed9-a670-77ec7544d1b9.png

Then click a Star

If you can’t get in, go in here

https://gitee.com/Lyon1998/pikascript (also available in China)

_images/139675170-fe0ce449-872f-466e-8780-74465730178a.png

Then also click a Star

Well, after you click on Star, we will start the next step.

We scroll down from the homepage of the code repository, see Get PikaScript, and then click PikaPackage.exe to download the package manager for pikascript.

_images/139675454-596829d1-0325-42ab-96c5-f3d3d369d7d4.png

Next, put PikaPackage.exe on the disk where you want to download PikaScript. In order to save your C drive, you can put PikaPackage.exe on the D drive, which can be any location on the D drive.

Double-click PikaPackage.exe, and the package manager will automatically download the latest PikaScript to the D:/tmp/pikascript folder for you. (If it is placed on the C drive, it will be downloaded to C:/tmp/pikascript)

The download uses domestic resources, does not require scientific Internet access, and the speed should be very good.

After downloading, you can delete this pikaPackage.exe.

If everything goes well, you can find the downloaded pikascript code repository in the /tmp/pikascript folder.

_images/139676635-c3f1c6ae-ab44-42a5-ab9a-9bedd2383f31.png

We enter the bsp folder and copy a copy of simulation-rtt-qemu-arm2d out.

_images/139677151-33c1dbd0-c2f2-4ea3-a5ae-569e5a448cce.png

So far, the project is ready to be ok.

2.9.3. Install the development environment

After you have the project, you also need to install the development environment. There are only two things that need to be installed. One is rt-thread studio, which is used as an IDE. rt-thread studio integrates qemu, which is very convenient for simulating mcu and gui. The other is the latest arm gcc toolchain.

2.9.4. Pull the module and precompile

We enter the simulation-rtt-qemu-arm2d/packages/pikascrpt directory, which is the pikascrit file.

_images/139678258-e2cdc50d-475b-435a-af8c-7c19cc3a218d.png

For the convenience of version management, pikascript uses request.txt to manage the version of the kernel and modules, so there is no source code of pikascript in this folder, only a requestment.txt file. If you are familiar with pip, you will find this file and the version used by pip The description file is exactly the same.

_images/139678404-9b747c0a-6508-4f6d-b0ca-671560f31fbd.png

We double-click to run pikaPackage.exe in this folder, and the kernel and modules of pikascript are pulled down.

_images/139678437-a77b7278-cafd-485e-b353-94a12302c8cb.png

This is what it looks like after pulling it down.

_images/139678713-0cd86aef-2996-4898-931d-68c805534312.png

Finally, we run rust-msc-latest-win10.exe to precompile, and it’s OK.

_images/139678750-befc11e9-d812-4fcf-949e-64dd873d0211.png

2.9.5. run

We open RT-Thread Studio and click Import

_images/139679061-2e3b2ea0-8e9a-44c9-9a0f-6f40d82a0208.png

Then select the simulation-rtt-qemu-arm2d folder

_images/139679380-3a45f426-e575-4142-b5f1-76439c7efc38.png

Select the project, then click the hammer to compile, and then click the bug to enter the simulation

_images/139679532-e19ed911-c7f4-4840-a5e3-f5b66905a62f.png

A QEMU box will pop up, then click Run.

_images/139679756-cb099fc9-c3e9-4b76-9037-38392350530b.png

If the operation is successful, you can see a small blue square on the white background. So far the deployment has been successful.

_images/139679797-3ce8f253-beb9-480f-90ee-1844500a77ab.png

2.9.6. Modify the python code and try

The source code of python is in simulation-rtt-qemu-arm2d/packages/pikascript/main.py, you can open it and see~

_images/139679915-45d1362e-7066-4829-ae83-b4bbc5d0aaa0.png

The following is the content of main.py, create a new box object, and then set the color and position, you can try to change the color to ‘white’ or change the coordinates to see, you can also create another screen.elems.b2 try .


import PikaStdLib
import Arm2D

mem = PikaStdLib.MemChecker()

win = Arm2D.Window()
win.init()
win.background.setColor('white')

win.elems.b1 = Arm2D.Box()
win.elems.b1.init()
win.elems.b1.setColor('blue')
win.elems.b1.move(100, 100)
i = 0
x0 = 100
y0 = 100
sizeX0 = 50
sizeY0 = 50
alpha0 = 180
isIncrace = 1
loopTimes = 0

print('hello pikaScript')
print('mem used max:')
mem.max()
print('mem used now:')
mem.now()
while True:
    win.elems.b1.move(x0 + i * 2, y0 + i * 1)
    win.elems.b1.setAlpha(alpha0 - i * 1)
    win.elems.b1.setSize(sizeX0 + i * 2, sizeY0 + i * 1)
    win.update()
    if isIncrace > 0:
        i = i + 1
        if i > 160:
            isIncrace = 0
    if isIncrace < 1:
        i = i - 1
        if i < 0:
            isIncrace = 1
            loopTimes = loopTimes + 1

Remember to precompile after each modification to convert python to .c file in the project

https://user-images.githubusercontent.com/88232613/171087328-3ff8f8be-2415-4a24-9c5f-b4b4fe6e81e6.png

Then compile again, enter the simulation, and you can see the effect. This time I changed the square to red.

_images/139680521-20f83ee3-2163-4649-ad23-ae73b77f482e.png

2.9.7. Conclusion

This is the Arm-2D warehouse~ Students who haven’t starred remember to add a star~

https://github.com/ARM-software/EndpointAI

_images/139681272-73a1a8c2-2889-4dab-bd05-7174cb14334c.png

Thanks to liuduanfei for the rtt-Arm2d-qemu simulation project~ Here is the github homepage of liuduanfei

_images/139681543-99a64e9b-eb10-4c8e-bbe3-e8170c85385a.png

https://github.com/liuduanfei