2023-03-02 10:10:22 +08:00
2023-03-02 10:10:22 +08:00
2023-02-12 19:53:06 +08:00
2023-01-15 09:08:10 +00:00
2023-02-27 14:20:21 +08:00
2023-02-28 10:59:53 +08:00
2023-03-02 00:35:14 +08:00
2023-03-02 00:35:14 +08:00
2023-03-01 22:15:22 +08:00
2023-03-01 15:47:25 +08:00
2022-01-04 01:51:32 +08:00
2021-09-26 09:10:22 +08:00
2022-11-23 23:58:14 +08:00
2022-03-27 10:21:40 +08:00
2021-11-26 00:00:41 +08:00
2023-02-26 21:14:45 +08:00
2023-02-27 14:20:21 +08:00
2023-03-02 10:10:22 +08:00
2021-12-06 21:04:12 -05:00

logo

PikaPython

Cross platform ultra lightweight embedded Python engine

中文页 | Forum | Documents | Videos | BSP | Package Manager | RT-Thread package | Contribute | Business

image

1. Abstract

PikaPython is an ultra-lightweight Python engine with zero dependencies and zero-configuration, that can run with 4KB of RAM (such as STM32G030C8 and STM32F103C8).

PikaPython also known as PikaScript and PikaPy.

It's very easy to bind C function to python module with the help of Pika Pre-compiler.Only write the API of python in .pyi and the bindings are autoly generated by Pre-compiler.

The Pre-compiler is fully open-source, and the source code is in the tools folder.

image-20220520233540245

Customized service

We provide one-stop customized services for hardware, software, cloud platform and mass production to help customers complete products quickly, economically and reliably.

Email us: liang6516@outlook.com

Get pikapython:

Use Online Project Generator

Generator url: http://pikascript.com

Note: You need the Community Edition license (Now Free) to build Keil projects, and the version of Keil should be newer than v5.36.

Use Pika package manager PikaPackage.exe

  1. Run the PikaPackage.exe directly, then the pikapython repo would be downloaded auto in the /tmp/pikascript folder of your current disc partition.

  2. Add requestment.txt to the same folder of PikaPackage.exe then run PikaPackage.exe. The run-time core, pre-compiler and moudles would be installed in the current folder.

  3. Released modulespackages.toml

Quick Start

You can use simulation project to quick start without hardwareor use the out-of-the-box develop board Pika-Pi—Zero.

image

The board based on STM32G030C8T6 MCU, only 64kB Flash, 8kB RAM can run pikapython with total peripheral device (GPIO、TIME、IIC、RGB、KEY、LCD、RGB). CH340 is deployed to support USB to serial with Type-C USB, support download python script py serial, there are 4 RGB on the board and support the LCD.

Related Projects

Document

https://pikadoc.readthedocs.io/en/latest/index.html

How to contribute

https://pikadoc.readthedocs.io/en/latest/%E5%A6%82%E4%BD%95%E5%8F%82%E4%B8%8E%E7%A4%BE%E5%8C%BA%E8%B4%A1%E7%8C%AE.html

Folders

src - core code

bsp - mcu/board support

port - OS and package manager

test - unit test

document - developt document

examples - example scripts

package - packages and moudles

pikaCompiler - pre-compiler write by Rust, used to bind C function to python moudle.

pikaPackageManager - pacakge manager

2.Platform support

MCU support

MCU bsp gpio time uart pwm adc i2c dac
stm32g030c8
stm32g070cB
stm32f103c8
stm32f103rb
stm32f103ze
stm32f103rc
stm32f401cc
stm32f411ce
stm32f407ze
stm32f407zg
stm32h750vb
stm32f051r8
air32f103cb
ch582
ch32v103r8t6
cm32m101a
w806
apm32f030r8
apm32e103vb
bl-602
bl-706
Raspberry Pico
ESP32C3
TC264D
devc
visual-studio
EC600N
mm32f5277e9p
xr806(openharmony)

Board support

Board bsp gpio uart pwm adc i2c rgb lcd arm-2d
Pika-Pi-Zero
Board bsp pika_lvgl
lvgl-vs-simu
swm320
Board bsp arm-2d
QEMU-arm2d
Board bsp LED KEY
SmartLoong

OS support

OS port GPIO TIME PWM
RT-Thread
vsf
OS port Google Test Benchmark
linux

3.Characteristic

(1)Run environment

Support run in mcu without OS or file system. Can run in everywhere with RAM ≥ 4kB and FLASH ≥ 64kBsuch as stm32g030, stm32f103c8t6esp8266.

(2)Develop enviroment

Support REPL by serial.

微信交流群

Support run and program python scripts by serial.

微信交流群

Support IDEs like Keil, IAR, RT-Thread studio and segger embedded studio to develop C moudle.

Support build tools like CMake, makeFile and Scons.

Zero dependencies, zero configuration, out-of-the-box, easy to integrated into privious C projcet.

Eazy to extern customized C moudles.

Support linux.

(3)Syntax

Support subaggregate of python 3 standard syntax.

Support class and method define, encapsulation-inheritance-polymorphism and moudles in .pyi of C module.

Syntax Compile-Time Run-Time Shell
Module Define - -
Module Import
Class Define
Class Inherit
Method Define
Method Override
Method Invoke
Argument Define
Argument Assignment
Object New
Object Free
Object Nest
Control flow

Operator

+ - * / == > < >= <= % ** // != & >> << and or not in += -= *= /=

Control flow

Syntax State
if
while
for in [list]
for in range(a, b)
for in [dict]
if elif else
for break/continue
while break/continue

Module

Syntax Python Module C Module
import [module]
import [module] as -
from [module] import [class/function>] -
from [module] import [class/function>] as -
from [module] import * - PikaObj Module Only

List/Dict

Syntax State
l = list()
l = [a, b, c]
d = dict()
d = {'a':x, 'b':y, 'c':z}

Exception

Syntax State
try:
except:
except [Exception]: -
except [Exception] as [err]: -
except: ... else: -
raise:
raise [Exception]: -
finally: -

Slice

Syntax str bytes list
test[i]
test[a : b]
test[a :]

Other keywords/Syntax

yield is comprehensions
- -

(4)Develop standard.

Readability first, nearly never use macro function and global argument.

Complete unit testes based on google test.

4.Both talk and show the code

E-mail: liang6516@outlook.com

5.Demo

The scripts in demos are in the examples folder.

Demo 01 GPIO

View Code
import PikaStdLib
import STM32G0

mem = PikaStdLib.MemChecker()
io1 = STM32G0.GPIO()
time = STM32G0.Time()

io1.setPin('PA8')
io1.setMode('out')
io1.enable()
io1.low()

print('hello pikapython')
print('mem.max :')
mem.max()
print('mem.now :')
mem.now()

while True:
    io1.low()
    time.sleep_ms(500)
    io1.high()
    time.sleep_ms(500)

Hnet-image (2)

Demo 02 USART

View Code
import PikaStdLib
import STM32G0

time = STM32G0.Time()
uart = STM32G0.UART()
uart.setId(1)
uart.setBaudRate(115200)
uart.enable()

while True:
    time.sleep_ms(500)
    readBuff = uart.read(2)
    print('read 2 char:')
    print(readBuff)

Hnet-image (3)

Demo 03 ADC

View Code
import PikaStdLib
import STM32G0

time = STM32G0.Time()
adc1 = STM32G0.ADC()

adc1.setPin('PA1')
adc1.enable()

while True:
    val = adc1.read()
    print('adc1 value:')
    print(val)
    time.sleep_ms(500)

mmexport1631351523907

Demo 04 PWM output

View Code ``` python import PikaStdLib import STM32G0

time = STM32G0.Time() pwm = STM32G0.PWM() pwm.setPin('PA8') pwm.setFrequency(2000) pwm.setDuty(0.5) pwm.enable()

while True: time.sleep_ms(500) pwm.setDuty(0.5) time.sleep_ms(500) pwm.setDuty(0.001)


</details>

## Demo 05 RGB

<details>

``` python
import STM32G0
import PikaPiZero
import PikaStdLib

rgb = PikaPiZero.RGB()
mem = PikaStdLib.MemChecker()

rgb.init()
rgb.enable()

print('hello 2')
print('mem used max:')
mem.max()

while True:
    print('flowing')
    rgb.flow()

Demo 06 Snake(Need LCD)

View Code ``` python from PikaObj import * import PikaStdLib import PikaPiZero import STM32G0

hardware init

lcd = PikaPiZero.LCD() lcd.init() lcd.clear('white') key = PikaPiZero.KEY() key.init() time = STM32G0.Time() x_max = 120 y_max = 150

snake init

s = PikaPiZero.Point() w = 9 h = 9 s.x = 50 s.y = 10 len = 0 while len < 3: b = s i = 0 while i < len: b = b.next i = i + 1 b.next = PikaPiZero.Point() b.next.x = b.x - 10 b.next.y = b.y b.next.prev = b len = len + 1

ring link

b.next = s s.prev = b

i = 0 b = s while i < len: lcd.fill(b.x, b.y, w, h, 'blue') b = b.next i = i + 1

print('snake lengh') print(len)

fruit init

f = PikaPiZero.Point() f.x = 30 f.y = 20 lcd.fill(f.x, f.y, w, h, 'green')

memory check

mem = PikaStdLib.MemChecker() print('mem used max:') mem.max()

main loop

d = 0 isUpdate = 1 isEat = 0 while True: if isUpdate: # isUpdate = 0 # check eat fruit if f.x == s.x and f.y == s.y: # have eat fruit isEat = 1 f.x = f.x + 30 if f.x > x_max: f.x = f.x - x_max f.y = f.y + 30 if f.y > y_max: f.y = f.y - y_max lcd.fill(f.x, f.y, w, h, 'green') # move snake by the direction if d == 0: x_new = s.x + 10 y_new = s.y if x_new > x_max: x_new = 0 elif d == 1: x_new = s.x y_new = s.y - 10 if y_new < 0: y_new = y_max elif d == 2: x_new = s.x y_new = s.y + 10 if y_new > y_max: y_new = 0 elif d == 3: x_new = s.x - 10 y_new = s.y if x_new < 0: x_new = x_max if isEat: isEat = 0 b_new = PikaPiZero.Point() b_new.x = x_new b_new.y = y_new b_new.prev = s.prev b_new.next = s s.prev.next = b_new s.prev = b_new s = b_new len = len + 1 print('snake lengh') print(len) print('mem used max:') mem.max() # drow the snake and fruit # clear last body lcd.fill(s.prev.x, s.prev.y, w, h, 'white') # new body s.prev.x = x_new s.prev.y = y_new # head is last body s = s.prev lcd.fill(s.x, s.y, w, h, 'blue') b = s i = 0 # scan key key_val = key.get() if key_val == 0: d = 0 isUpdate = 1 elif key_val == 1: d = 1 isUpdate = 1 elif key_val == 2: d = 2 isUpdate = 1 elif key_val == 3: d = 3 isUpdate = 1


</details>

![image](https://user-images.githubusercontent.com/88232613/150269059-1fe3d62d-0c1b-40f4-9298-0d787f476a20.png)

The maximum RAM usage of these demos is only 3.56K, which is 4.56K if the 1K stack is included, and the maximum Flash usage is 30.4K. Refer to the 20K RAM and 64K Flash of STM32F103C8T6, less than 25% RAM and less than 50% Flash are used.

A quick comparison can be made between the microPython's MCU STM32F405RG and the pikapython's MCU STM32G070CB.

## RAM resource comparison
![image](document/image/132944731-a55ece1d-061f-4b91-ba87-bd6547be96a7.png)

## Flash Resource Comparison
![image](document/image/132944745-e9cf598d-e75f-40bb-873e-911819d535b7.png)

## Reference price comparison (take the selling price of 10 pieces in Lichuang Mall on September 11, 2021 as reference)
![image](document/image/132944757-2b5cfda8-f93f-4456-8d7f-4e4767954056.png)

## About the custom extern module 

In addition to device drivers, developing custom Python modules for MCU is very easy. The following two demos are extensions of the custom module, which developed python interfaces for the ARM-2D image driver library.

## Boxes~
![Hnet-image (7)](document/image/132945282-bfd310df-8063-456d-b90c-6b798a2c8ed5.gif)

## Rotating suns~
![Hnet-image (6)](document/image/132945107-e473a2cc-9fbc-47f9-aaed-a28d3ad1048c.gif)

# 6.Test and develop Core

## Test core in docker (recommend)
[get start with docker](https://pikadoc.readthedocs.io/en/latest/get-start_linux.html)

# ✨ Contributors

<a href="https://github.com/pikastech/pikapython/graphs/contributors">
  <img src="https://contrib.rocks/image?repo=pikastech/pikascript" />
</a>

## [How to contribute](https://pikadoc.readthedocs.io/en/latest/%E5%A6%82%E4%BD%95%E5%8F%82%E4%B8%8E%E7%A4%BE%E5%8C%BA%E8%B4%A1%E7%8C%AE.html)

| Contributer | [Achivements](document/achivement.md) |
| ----------------------------------------------------- | :----------------------------------------------------------- |
| [甜航](https://github.com/easyzoom)                   | <img src="assets/26.png" alt="26" width="80" /> |
| 千帆(微信名)                                          | <img src="assets/26.png" alt="26" width="80" /> |
| [ Meco Jianting Man](https://github.com/mysterywolf)  | <img src="assets/22.png" alt="12" width="80" /><img src="assets/26.png" alt="26" width="80" /><img src="assets/23.png" alt="23" width="80" /><img src="assets/15.png" alt="15" width="80" /><img src="assets/11.png" alt="15" width="80" /><img src="assets/41.png" alt="41" width="80" />|
| [liuduanfei](https://github.com/liuduanfei)           | <img src="assets/26.png" alt="26" width="80" /> |
| [ sjy](https://gitee.com/shanjiayang)                 | <img src="assets/26.png" alt="26" width="80" /><img src="assets/13.png" alt="13" width="80" /> |
| 沧御                                                  | <img src="assets/26.png" alt="26" width="80" /> |
| [versaloon](https://github.com/versaloon)             | <img src="assets/26.png" alt="26" width="80" /><img src="assets/13.png" alt="13" width="80" /> |
| 刘延(微信名)                                          | <img src="assets/36.png" alt="36" width="80" /><img src="assets/41-16594077379821.png" alt="41" width="80" /> |
| [GorgonMeducer](https://github.com/GorgonMeducer)     | <img src="assets/25.png" alt="25" width="80" /><img src="assets/22.png" alt="22" width="80" /><img src="assets/21.png" alt="21" width="80" /><img src="assets/33.png" alt="33" width="80" /><img src="assets/41-16594077379821.png" alt="41" width="80" /> |
| [unsigned](https://gitee.com/unsigned0)               | <img src="assets/26.png" alt="26" width="80" /><img src="assets/23.png" alt="23" width="80" /> |
| [梦程MI](https://gitee.com/dreamcmi)                  | <img src="assets/36.png" alt="36" width="80" /><img src="assets/23.png" alt="23" width="80" /><img src="assets/41-16594077379821.png" alt="41" width="80" /> |
| [Maximilian Gerhardt](https://github.com/maxgerhardt) | <img src="assets/12.png" alt="12" width="80" /> |
| [purewind7](https://gitee.com/purewind7)              | <img src="assets/24.png" alt="24" width="80" /><img src="assets/31.png" alt="31" width="80" /><img src="assets/33.png" alt="33" width="80" /><img src="assets/41-16594077379821.png" alt="41" width="80" /> |
| [ onceday](https://gitee.com/onceday)                 | <img src="assets/24.png" alt="24" width="80" /><img src="assets/13.png" alt="13" width="80" /> |


<div class="log"></div>

| Contribute log | Contributer |
| --- | --- |
| hmac hashlib base64 aes modules | [梦程MI](https://gitee.com/dreamcmi) |
| request module | [onceday](https://gitee.com/onceday) |
| mqtt module | [FlintJ](https://gitee.com/flintj) |
| Donate500¥ | [hardsofttech](https://gitee.com/hardsofttech) |
| Donate500¥ | [edmund_wz](https://gitee.com/edmund_wz) |
| Donate500¥ | [Meco Jianting Man](https://github.com/mysterywolf) |
| Donate500¥ | [hardsofttech](https://gitee.com/hardsofttech) |
| re module | [eglwang](https://gitee.com/eglwang) |
| PikaMath.Quaternion() | [purewind7](https://gitee.com/purewind7) |
| contrubute to PikaCV | [purewind7](https://gitee.com/purewind7) |
| xr806(openharmony) bsp |[sjy](https://gitee.com/shanjiayang)|
| ESP32 package |沧御|
| MM32F5277E9P package |[unsigned](https://gitee.com/unsigned0)|
| mm32f5277e9p BSP |[unsigned](https://gitee.com/unsigned0)|
| Add [CMSIS-PACK](https://pikadoc.readthedocs.io/en/latest/get-start_cmsis-pack.html) | [GorgonMeducer](https://github.com/GorgonMeducer) |
| donate: air32f103 board * 20 | 合宙 [xinxi204](https://gitee.com/xinxi204) |
| contrubute to PikaMath.Math() | [onceday](https://gitee.com/onceday) |
| add support for Unix Time | [onceday](https://gitee.com/onceday) |
| contrubute to PikaStdLib.String() | [purewind7](https://gitee.com/purewind7) |
| Add [PLOOC](https://github.com/GorgonMeducer/PLOOC) support for pikapython Core | [GorgonMeducer](https://github.com/GorgonMeducer) |
| Donate500¥ (ctypes 相关) | 蒋太平 |
| fix linux install script | [Maximilian Gerhardt](https://github.com/maxgerhardt) |
| ch582 package | [梦程MI](https://gitee.com/dreamcmi) |
| ch582 BSP | [梦程MI](https://gitee.com/dreamcmi) |
| DonateEC600X QuecPython Develop board| 移远通信 武加玉 |
| Performance Point: 900->1400 | [GorgonMeducer](https://github.com/GorgonMeducer) |
| stm32f051r8 BSP |[unsigned](https://gitee.com/unsigned0)|
| stm32f407ze BSP |[unsigned](https://gitee.com/unsigned0)|
| devc BSP |[unsigned](https://gitee.com/unsigned0)|
| TC264D BSP |[unsigned](https://gitee.com/unsigned0)|
| PikaVM improvement | [GorgonMeducer](https://github.com/GorgonMeducer) |
| W801Device package | 刘延(微信名) |
| W806 bsp | 刘延(微信名) |
| DonateESP32C3 5piclinker|启明云端 沧御|
| DonateLS1C101 mcu 10pic, LS1c101 develop boarddebuger|龙芯俱乐部 石南|
| PikaVSF OS package | [versaloon](https://github.com/versaloon) |
| ESP32C3 BSP |沧御|
| DonateESP32 board、ink lcd*4 | name(微信名) |
| Donatesmartloong board | 龙芯俱乐部 石南 |
| package/STM32F1 | [sjy](https://gitee.com/shanjiayang) |
| package/STM32F103RBBooter | [sjy](https://gitee.com/shanjiayang) |
| bsp/stm32f103rb | [sjy](https://gitee.com/shanjiayang) |
| QEMU ARM-2D simulation proejct | [liuduanfei](https://github.com/liuduanfei) |
| DonateGD32E103TB2 2 pic | 信息牛(微信名) |
| Rt-thread bsp、port、module| [Meco Jianting Man](https://github.com/mysterywolf) |
| DonateEC600S-CN 4G| 移远模块 |
| DonateBL706 board|博流智能 [bouffalolab](https://github.com/bouffalolab)|
| DonateCM32M101A 开发板| 孟巍(微信名) |
| DonateAPM32F030R8 board | 极海半导体 陈成 |
| DonateAPM32E103VB board | 极海半导体 陈成 |
| DonateAPEX-Link| 极海半导体 陈成 |
| corde formatadd gitattributes| [Meco Jianting Man](https://github.com/mysterywolf) |
| demo/simulation-keil | 千帆(微信名) |
| demo/stm32f103zet6/demo01-led-stm32f103zet6 | [甜航](https://github.com/easyzoom) |
| demo/stm32f103zet6/demo02-led-stm32f103zet6_tworoot | [甜航](https://github.com/easyzoom) |
| demo/stm32f407zgt/demo01-led-stm32f407vgt | [甜航](https://github.com/easyzoom) |


## Star History

[![Star History Chart](https://api.star-history.com/svg?repos=pikastech/pikascript&type=Date)](https://star-history.com/#pikastech/pikascript&Date)
Description
No description provided
Readme MIT 277 MiB
Languages
C 97.9%
Assembly 0.9%
Python 0.6%
C++ 0.2%
Shell 0.1%
Other 0.1%