2022-07-02 20:13:13 +08:00
<p align="center">
<img alt="logo" src="document/image/144221063-a85b2cb0-0416-493f-9afb-56cff31e977d.jpg" width="300">
</p>
2023-01-07 16:18:02 +08:00
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">PikaPython</h1>
2022-07-02 20:13:13 +08:00
<h4 align="center">Cross platform ultra lightweight embedded Python engine</h4>
<p align="center">
2023-01-07 16:16:28 +08:00
<a href="https://gitee.com/lyon1998/pikapython/stargazers"><img src="https://gitee.com/lyon1998/pikapython/badge/star.svg?theme=gvp"></a>
<a href="https://gitee.com/lyon1998/pikapython/members"><img src="https://gitee.com/lyon1998/pikapython/badge/fork.svg?theme=gvp"></a>
<a href="https://github.com/pikastech/pikapython/stargazers"><img src="https://img.shields.io/github/stars/pikastech/pikapython?style=flat-square&logo=GitHub"></a>
<a href="https://github.com/pikastech/pikapython/network/members"><img src="https://img.shields.io/github/forks/pikastech/pikapython?style=flat-square&logo=GitHub"></a>
<a href="https://github.com/pikastech/pikapython/watchers"><img src="https://img.shields.io/github/watchers/pikastech/pikapython?style=flat-square&logo=GitHub"></a>
<a href="https://github.com/pikastech/pikapython/issues"><img src="https://img.shields.io/github/issues/pikastech/pikapython.svg?style=flat-square&logo=GitHub"></a>
<a href="https://github.com/pikastech/pikapython/blob/master/LICENSE"><img src="https://img.shields.io/github/license/pikastech/pikapython.svg?style=flat-square"></a>
<a href="https://github.com/pikasTech/pikapython/actions/workflows/CI.yml"><img src="https://github.com/pikasTech/pikapython/actions/workflows/CI.yml/badge.svg"> </a>
2023-04-13 15:59:58 +08:00
<a href="https://app.codecov.io/gh/pikasTech/PikaPython"><img src="https://codecov.io/gh/pikasTech/PikaPython/branch/master/graph/badge.svg"> </a>
2022-07-02 20:13:13 +08:00
</p>
<p align="center">
<a href="README_zh.md" >中文页</a> |
<a href="https://whycan.com/f_55.html" >Forum</a> |
2023-07-19 10:54:07 +08:00
<a href="https://pikadoc-en.readthedocs.io/en/latest/index.html" >Documents</a> |
2022-07-02 20:13:13 +08:00
<a href="https://space.bilibili.com/5365336/channel/detail?cid=202329">Videos</a> |
<a href="../../tree/master/bsp#platform-support">BSP</a> |
2023-07-19 10:54:07 +08:00
<a href="https://pikadoc-en.readthedocs.io/en/latest/%E5%8C%85%E7%AE%A1%E7%90%86%E5%99%A8%E4%B8%8E%E6%A8%A1%E5%9D%97%E7%AE%A1%E7%90%86.html">Package Manager</a> |
<a href="https://pikadoc-en.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" >Contribute</a> |
<a href="https://pikadoc-en.readthedocs.io/en/latest/%E5%95%86%E4%B8%9A%E5%90%88%E4%BD%9C%E6%96%B9%E5%BC%8F.html">Business</a>
2022-07-02 20:13:13 +08:00
</p>
2023-03-08 10:14:56 +08:00
[![image](document/image/147997370-ff37b6e7-25b2-4174-aa64-c1fb92cede04.png)](https://pikastech.github.io/PikaPython/dev/bench/)
2022-07-02 20:13:13 +08:00
# 1. Abstract
2023-03-16 09:34:10 +08:00
PikaPython is an ultra-lightweight Python interpreter that runs with only 4KB of RAM, zero dependencies. It is ready to use out of the box without any configuration required and easy to extend with C.
2023-01-10 14:40:33 +08:00
PikaPython also known as PikaScript and PikaPy.
2022-07-02 20:13:13 +08:00
<img src="https://user-images.githubusercontent.com/88232613/147799704-d79345da-a2b9-4593-b1eb-ff9de127429a.png" width="500"/>
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.
![image-20220520233540245](document/image/image-20220520233540245.png)
2023-01-07 16:16:28 +08:00
# Get pikapython:
2022-07-02 20:13:13 +08:00
## Use Online Project Generator
Generator url:
http://pikascript.com
Note: You need the [Community Edition license (Now Free)](https://www.keil.com/pr/article/1299.htm) to build Keil projects, and the version of Keil should be newer than v5.36.
[![](assets/1644129110261-049ad5bb-21af-40e2-9533-a1c8c86790f1.jpg)](http://pikascript.com)
2023-08-23 11:53:58 +08:00
## PikaPython studio
PikaPython serial terminal, script download and package menage tool.
2022-07-02 20:13:13 +08:00
2023-08-23 11:53:58 +08:00
[![](assets/115.png)](https://gitee.com/Lyon1998/pikapython/attach_files/1285327/download)
2022-07-02 20:13:13 +08:00
# Quick Start
2023-09-09 15:32:16 +08:00
You can use [simulation project](https://pikadoc-en.readthedocs.io/en/latest/Keil%20%E4%BB%BF%E7%9C%9F%E5%B7%A5%E7%A8%8B.html) to quick start without hardware, or use the out-of-the-box develop board [Pika-Pi—Zero](https://item.taobao.com/item.htm?spm=a1z10.3-c.w4002-23991764791.11.37216340XZtYt9&id=738387991209).
2022-07-02 20:13:13 +08:00
![image](https://user-images.githubusercontent.com/88232613/141252834-93011ca7-f84b-4192-8e61-0e242796f62c.png)
2023-01-07 16:16:28 +08:00
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).
2022-07-02 20:13:13 +08:00
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](https://item.taobao.com/item.htm?spm=a1z10.3-c.w4002-23991764791.12.16f97c58fsLjVk&id=660745643102).
# Related Projects
2023-01-07 16:16:28 +08:00
- ▶️ [pikapython Binding For LVGL](https://github.com/lvgl/lv_binding_pikascript)
2022-11-03 15:38:17 +08:00
2023-01-07 16:16:28 +08:00
- ⭐ [pikapython Bluepill Demo In PlatformIO — Python-like REPL 🐍🔌](https://github.com/maxgerhardt/pikascript-pio-bluepill)
2022-07-02 20:13:13 +08:00
2023-01-07 16:16:28 +08:00
- ⭐ [pikapython Bluepill Demo In GCC 🐍](https://github.com/Chandler-Kluser/pikascript_gcc_bluepill)
2022-07-02 20:13:13 +08:00
2023-07-29 11:02:43 +08:00
- ⏩ [pika_startup_demo](https://gitee.com/kcfkwok/pika_startup_demo) This program demonstrate the 5 startup methods of pikapython.
- 🎮 [PikaPython-OpenHardware](https://gitee.com/Lyon1998/pikapython_openhardware) PikaPython 开源硬件
- 💻 [pikapython-msvc-qt](https://gitee.com/zuto360_460135301/pikapython-msvc-qt) 移植pikapython到windows平台, 基于QT, 采用MSVC编译器, 移植pthread库, 支持多线程。
2022-07-02 20:13:13 +08:00
# Document
2023-07-19 10:54:07 +08:00
https://pikadoc-en.readthedocs.io/en/latest/index.html
2022-07-02 20:13:13 +08:00
## How to contribute
2023-07-19 10:54:07 +08:00
https://pikadoc-en.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
2022-07-02 20:13:13 +08:00
## Folders
[src](../../tree/master/src) - core code
[bsp](../../tree/master/bsp) - mcu/board support
2022-08-27 15:01:12 +08:00
[port](../../tree/master/port) - OS and package manager
[test](../../tree/master/port/linux/test) - unit test
2022-07-02 20:13:13 +08:00
[document](../../tree/master/document) - developt document
[examples](../../tree/master/examples) - example scripts
[package](../../tree/master/package) - packages and moudles
[pikaCompiler](../../tree/master/tools/pikaCompiler) - pre-compiler write by Rust, used to bind C function to python moudle.
[pikaPackageManager](../../tree/master/tools/pikaPackageManager) - pacakge manager
# 2.Platform support
## MCU support
!INCLUDE "bsp.mdpp"
## Board support
!INCLUDE "board.mdpp"
## OS support
!INCLUDE "os.mdpp"
# 3.Characteristic
### (1)Run environment
2023-01-10 14:43:48 +08:00
Support run in mcu without OS or file system. Can run in everywhere with **RAM ≥ 4kB** and **FLASH ≥ 64kB**, such as stm32g030, stm32f103c8t6, esp8266.
2022-07-02 20:13:13 +08:00
### (2)Develop enviroment
#### Support REPL by serial.
<img src="assets/1641178790145-2f026e70-4ba1-4e9a-b05f-c602b2bd8cad.png" width="400" alt="微信交流群"/><br/>
#### Support run and program python scripts by serial.
<img src="document/image/134841230-85de6734-8467-4245-93a5-d452b5022b42.gif" width="400" alt="微信交流群"/><br/>
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.
2023-03-02 10:15:32 +08:00
<details><summary>More Details About Syntax Support</summary>
2022-07-02 20:13:13 +08:00
|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 |√|√|√|
!INCLUDE "syntax.mdpp"
2023-03-02 10:15:32 +08:00
</details>
2022-07-02 20:13:13 +08:00
### (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](examples) folder.
## Demo 01 GPIO
2023-03-02 10:15:32 +08:00
<details><summary>View Code</summary>
2023-03-02 10:10:22 +08:00
2022-07-02 20:13:13 +08:00
``` python
import PikaStdLib
import STM32G0
mem = PikaStdLib.MemChecker()
io1 = STM32G0.GPIO()
time = STM32G0.Time()
io1.setPin('PA8')
io1.setMode('out')
io1.enable()
io1.low()
2023-01-07 16:16:28 +08:00
print('hello pikapython')
2022-07-02 20:13:13 +08:00
print('mem.max :')
mem.max()
print('mem.now :')
mem.now()
while True:
io1.low()
time.sleep_ms(500)
io1.high()
time.sleep_ms(500)
```
2023-03-02 10:10:22 +08:00
2023-03-02 10:05:23 +08:00
</details>
2022-07-02 20:13:13 +08:00
![Hnet-image (2)](document/image/132943428-f2b365ca-140e-42f4-936c-db6a7d9f8dee.gif)
## Demo 02 USART
2023-03-02 10:15:32 +08:00
<details><summary>View Code</summary>
2023-03-02 10:10:22 +08:00
2022-07-02 20:13:13 +08:00
``` python
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)
```
2023-03-02 10:10:22 +08:00
2023-03-02 10:05:23 +08:00
</details>
2022-07-02 20:13:13 +08:00
2023-03-11 23:58:13 +08:00
![Hnet-image (3)](document/image/132943365-0f7059b3-4f9d-4989-a5ec-2cce72b0cc96.gif)
2022-07-02 20:13:13 +08:00
## Demo 03 ADC
2023-03-02 10:05:23 +08:00
<details>
2023-03-02 10:10:22 +08:00
2023-03-02 10:08:09 +08:00
<summary>View Code</summary>
2023-03-02 10:10:22 +08:00
2022-07-02 20:13:13 +08:00
``` python
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)
```
2023-03-02 10:10:22 +08:00
2023-03-02 10:05:23 +08:00
</details>
2022-07-02 20:13:13 +08:00
![mmexport1631351523907](document/image/132944185-0a01b1ba-8cf7-4f9f-9d73-fe9cbcd52f0b.png)
## Demo 04 PWM output
2023-03-02 10:12:22 +08:00
<details><summary>View Code</summary>
2023-03-02 10:10:22 +08:00
2022-07-02 20:13:13 +08:00
``` 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)
```
2023-03-02 10:10:22 +08:00
2023-03-02 10:05:23 +08:00
</details>
2022-07-02 20:13:13 +08:00
## Demo 05 RGB
2023-03-02 10:15:32 +08:00
<details><summary>View Code</summary>
2023-03-02 10:10:22 +08:00
2022-07-02 20:13:13 +08:00
``` 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()
```
2023-03-02 10:10:22 +08:00
2023-03-02 10:05:23 +08:00
</details>
2022-07-02 20:13:13 +08:00
## Demo 06 Snake(Need LCD)
2023-03-02 10:05:23 +08:00
<details>
2023-03-02 10:10:22 +08:00
2023-03-02 10:08:09 +08:00
<summary>View Code</summary>
2023-03-02 10:12:22 +08:00
2022-07-02 20:13:13 +08:00
``` 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
2023-03-02 10:15:32 +08:00
2022-07-02 20:13:13 +08:00
```
2023-03-02 10:10:22 +08:00
2023-03-02 10:05:23 +08:00
</details>
2022-07-02 20:13:13 +08:00
![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.
## 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)
2023-07-19 10:54:07 +08:00
[get start with docker](https://pikadoc-en.readthedocs.io/en/latest/get-start_linux.html)
2022-07-02 20:13:13 +08:00
# ✨ Contributors
2023-01-07 16:16:28 +08:00
<a href="https://github.com/pikastech/pikapython/graphs/contributors">
2023-01-07 16:18:02 +08:00
<img src="https://contrib.rocks/image?repo=pikastech/pikascript" />
2022-07-02 20:13:13 +08:00
</a>
2023-07-19 10:54:07 +08:00
## [How to contribute](https://pikadoc-en.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)
2022-07-02 20:13:13 +08:00
2022-08-02 13:28:49 +08:00
<div class="log"></div>
2023-03-02 10:45:44 +08:00
### Contribute Log On 2023
| Contribute log | Contributer |
| --- | --- |
!INCLUDE "contributor2023.mdpp"
<details><summary> Contribute Log On 2022 </summary>
| Contribute log | Contributer |
| --- | --- |
!INCLUDE "contributor2022.mdpp"
</details>
<details><summary> Contribute Log On 2021 </summary>
2022-07-02 20:13:13 +08:00
| Contribute log | Contributer |
| --- | --- |
2023-03-02 10:45:44 +08:00
!INCLUDE "contributor2021.mdpp"
2022-07-02 20:13:13 +08:00
2023-03-02 10:45:44 +08:00
</details>
2022-07-02 20:13:13 +08:00
## Star History
2023-01-07 16:18:02 +08:00
[![Star History Chart](https://api.star-history.com/svg?repos=pikastech/pikascript&type=Date)](https://star-history.com/#pikastech/pikascript&Date)