- Notifications
You must be signed in to change notification settings - Fork0
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. Similar project: MicroPython, JerryScript.
License
IVOES/PikaPython
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
中文页 |Forum |Documents |Videos |BSP |Package Manager |Contribute |Business
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.
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.
Generator url:http://pikascript.com
Note: You need theCommunity Edition license (Now Free) to build Keil projects, and the version of Keil should be newer than v5.36.
Use Pika package managerPikaPackage.exe
Run thePikaPackage.exe directly, then the pikapython repo would be downloaded auto in the /tmp/pikascript folder of your current disc partition.
Addrequestment.txt to the same folder of PikaPackage.exe then runPikaPackage.exe. Therun-time core,pre-compiler andmoudles would be installed in the current folder.
Released modules:packages.toml
You can usesimulation project to quick start without hardware,or use the out-of-the-box develop boardPika-Pi—Zero.
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 theLCD.
https://pikadoc.readthedocs.io/en/latest/index.html
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
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 | √ | |||||||
bl-618 | √ | √ | √ | √ | √ | √ | √ | √ |
Raspberry Pico | √ | |||||||
ESP32C3 | √ | √ | √ | |||||
TC264D | √ | |||||||
devc | √ | |||||||
visual-studio | √ | |||||||
EC600N | √ | |||||||
mm32f5277e9p | √ | √ | ||||||
xr806(openharmony) | √ |
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 | port | GPIO | TIME | PWM |
---|---|---|---|---|
RT-Thread | √ | √ | √ | √ |
vsf | √ | √ |
OS | port | Google Test | Benchmark |
---|---|---|---|
linux | √ | √ | √ |
Support run in mcu without OS or file system. Can run in everywhere withRAM ≥ 4kB andFLASH ≥ 64kB,such as stm32g030, stm32f103c8t6,esp8266.
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.
Support subaggregate of python 3 standard syntax.
Support class and method define, encapsulation-inheritance-polymorphism and moudles in.pyi
of C module.
More Details About Syntax Support
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 | √ | √ | √ |
+ | - | * | / | == | > | < | >= | <= | % | ** | // | != | & | >> | << | and | or | not | in | += | -= | *= | /= |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
√ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ |
Syntax | State |
---|---|
if | √ |
while | √ |
for in [list] | √ |
for in range(a, b) | √ |
for in [dict] | √ |
if elif else | √ |
for break/continue | √ |
while break/continue | √ |
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 |
Syntax | State |
---|---|
l = list() | √ |
l = [a, b, c] | √ |
d = dict() | √ |
d = {'a':x, 'b':y, 'c':z} | √ |
Syntax | State |
---|---|
try: | √ |
except: | √ |
except [Exception]: | - |
except [Exception] as [err]: | - |
except: ... else: | - |
raise: | √ |
raise [Exception]: | - |
finally: | - |
Syntax | str | bytes | list |
---|---|---|---|
test[i] | √ | √ | √ |
test[a : b] | √ | √ | √ |
test[a :] | √ | √ | √ |
yield | is | comprehensions |
---|---|---|
- | √ | - |
Readability first, nearly never use macro function and global argument.
Complete unit testes based on google test.
E-mail:liang6516@outlook.com
The scripts in demos are in theexamples folder.
View Code
importPikaStdLibimportSTM32G0mem=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()whileTrue:io1.low()time.sleep_ms(500)io1.high()time.sleep_ms(500)
View Code
importPikaStdLibimportSTM32G0time=STM32G0.Time()uart=STM32G0.UART()uart.setId(1)uart.setBaudRate(115200)uart.enable()whileTrue:time.sleep_ms(500)readBuff=uart.read(2)print('read 2 char:')print(readBuff)
View Code
importPikaStdLibimportSTM32G0time=STM32G0.Time()adc1=STM32G0.ADC()adc1.setPin('PA1')adc1.enable()whileTrue:val=adc1.read()print('adc1 value:')print(val)time.sleep_ms(500)
View Code
importPikaStdLibimportSTM32G0time=STM32G0.Time()pwm=STM32G0.PWM()pwm.setPin('PA8')pwm.setFrequency(2000)pwm.setDuty(0.5)pwm.enable()whileTrue:time.sleep_ms(500)pwm.setDuty(0.5)time.sleep_ms(500)pwm.setDuty(0.001)
View Code
importSTM32G0importPikaPiZeroimportPikaStdLibrgb=PikaPiZero.RGB()mem=PikaStdLib.MemChecker()rgb.init()rgb.enable()print('hello 2')print('mem used max:')mem.max()whileTrue:print('flowing')rgb.flow()
View Code
fromPikaObjimport*importPikaStdLibimportPikaPiZeroimportSTM32G0# hardware initlcd=PikaPiZero.LCD()lcd.init()lcd.clear('white')key=PikaPiZero.KEY()key.init()time=STM32G0.Time()x_max=120y_max=150# snake inits=PikaPiZero.Point()w=9h=9s.x=50s.y=10len=0whilelen<3:b=si=0whilei<len:b=b.nexti=i+1b.next=PikaPiZero.Point()b.next.x=b.x-10b.next.y=b.yb.next.prev=blen=len+1# ring linkb.next=ss.prev=bi=0b=swhilei<len:lcd.fill(b.x,b.y,w,h,'blue')b=b.nexti=i+1print('snake lengh')print(len)# fruit initf=PikaPiZero.Point()f.x=30f.y=20lcd.fill(f.x,f.y,w,h,'green')# memory checkmem=PikaStdLib.MemChecker()print('mem used max:')mem.max()# main loopd=0isUpdate=1isEat=0whileTrue:ifisUpdate:# isUpdate = 0# check eat fruitiff.x==s.xandf.y==s.y:# have eat fruitisEat=1f.x=f.x+30iff.x>x_max:f.x=f.x-x_maxf.y=f.y+30iff.y>y_max:f.y=f.y-y_maxlcd.fill(f.x,f.y,w,h,'green')# move snake by the directionifd==0:x_new=s.x+10y_new=s.yifx_new>x_max:x_new=0elifd==1:x_new=s.xy_new=s.y-10ify_new<0:y_new=y_maxelifd==2:x_new=s.xy_new=s.y+10ify_new>y_max:y_new=0elifd==3:x_new=s.x-10y_new=s.yifx_new<0:x_new=x_maxifisEat:isEat=0b_new=PikaPiZero.Point()b_new.x=x_newb_new.y=y_newb_new.prev=s.prevb_new.next=ss.prev.next=b_news.prev=b_news=b_newlen=len+1print('snake lengh')print(len)print('mem used max:')mem.max()# drow the snake and fruit# clear last bodylcd.fill(s.prev.x,s.prev.y,w,h,'white')# new bodys.prev.x=x_news.prev.y=y_new# head is last bodys=s.prevlcd.fill(s.x,s.y,w,h,'blue')b=si=0# scan keykey_val=key.get()ifkey_val==0:d=0isUpdate=1elifkey_val==1:d=1isUpdate=1elifkey_val==2:d=2isUpdate=1elifkey_val==3:d=3isUpdate=1
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.
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.
Contributer | Achivements |
---|---|
甜航 | ![]() |
千帆(微信名) | ![]() |
Meco Jianting Man | ![]() ![]() ![]() ![]() ![]() ![]() |
liuduanfei | ![]() |
sjy | ![]() ![]() |
沧御 | ![]() |
versaloon | ![]() ![]() |
刘延(微信名) | ![]() ![]() |
GorgonMeducer | ![]() ![]() ![]() ![]() ![]() |
unsigned | ![]() ![]() |
梦程MI | ![]() ![]() ![]() |
Maximilian Gerhardt | ![]() |
purewind7 | ![]() ![]() ![]() ![]() |
onceday | ![]() ![]() |
Contribute log | Contributer |
---|---|
support PIKA_UNBUFFERD_ENABLE config item | Seny Lee |
addthis module | blueloveTH |
Fix memory leak in event queue | randyscott |
Fix a bug of _OP_POW | blueloveTH |
fix bsp/esp32/README.md | erzongxie |
Fixed a bug where help("modules") crashed when no lib was loaded | 梦程MI |
support GPIO driver for rt-thread | supperthomas |
Fixed a typo | J. Neuschäfer |
codecov CI support | Renzhihan |
rt-thread build script fix and improve | supperthomas |
support pikafs pack and unpack to path | sjy |
fix pika_platform_get_tick() in linux port | 梦程MI |
CH307开发板、BL618开发板 | VeriMake |
VM instruction extension framework | GorgonMeducer |
iotcloud module | 梦程MI |
implement shell filter | GorgonMeducer |
修复socket模块在lwip中fcntl的参数数量错误 | 梦程MI |
support GPIO pika_hal for BLMCU | codercmd |
Fix Typo on PikaVM.c | Ikko Eltociear Ashimine |
Fix type assert on dataArgs.c | itschina |
add examples/Device/KEY_POLL.PY | codercmd |
hmac hashlib base64 aes modules | 梦程MI |
fix pikaCompiler build error on macos | 梦程MI |
Contribute Log On 2022
Contribute log | Contributer |
---|---|
request module | onceday |
mqtt module | FlintJ |
Donate:500¥ | hardsofttech |
Donate:500¥ | edmund_wz |
Donate:500¥ | Meco Jianting Man |
Donate:500¥ | hardsofttech |
PikaNN module | Renzhihan |
re module | eglwang |
PikaMath.Quaternion() | purewind7 |
contrubute to PikaCV | purewind7 |
xr806(openharmony) bsp | sjy |
ESP32 package | 沧御 |
MM32F5277E9P package | unsigned |
mm32f5277e9p BSP | unsigned |
AddCMSIS-PACK | GorgonMeducer |
donate: air32f103 board * 20 | 合宙xinxi204 |
contrubute to PikaMath.Math() | onceday |
add support for Unix Time | onceday |
contrubute to PikaStdLib.String() | purewind7 |
AddPLOOC support for pikapython Core | GorgonMeducer |
Donate:500¥ (ctypes 相关) | 蒋太平 |
fix linux install script | Maximilian Gerhardt |
ch582 package | 梦程MI |
ch582 BSP | 梦程MI |
Donate:EC600X QuecPython Develop board | 移远通信 武加玉 |
Performance Point: 900->1400 | GorgonMeducer |
stm32f051r8 BSP | unsigned |
stm32f407ze BSP | unsigned |
devc BSP | unsigned |
TC264D BSP | unsigned |
PikaVM improvement | GorgonMeducer |
W801Device package | 刘延(微信名) |
W806 bsp | 刘延(微信名) |
Donate:ESP32C3 5pic,linker | 启明云端 沧御 |
Donate:LS1C101 mcu 10pic, LS1c101 develop board,debuger | 龙芯俱乐部 石南 |
PikaVSF OS package | versaloon |
ESP32C3 BSP | 沧御 |
Contribute Log On 2021
Contribute log | Contributer |
---|---|
Donate:ESP32 board、ink lcd*4 | name(微信名) |
Donate:smartloong board | 龙芯俱乐部 石南 |
package/STM32F1 | sjy |
package/STM32F103RBBooter | sjy |
bsp/stm32f103rb | sjy |
QEMU ARM-2D simulation proejct | liuduanfei |
Donate:GD32E103TB2 2 pic | 信息牛(微信名) |
Rt-thread bsp、port、module | Meco Jianting Man |
Donate:EC600S-CN 4G | 移远模块 |
Donate:BL706 board | 博流智能bouffalolab |
Donate:CM32M101A 开发板 | 孟巍(微信名) |
Donate:APM32F030R8 board | 极海半导体 陈成 |
Donate:APM32E103VB board | 极海半导体 陈成 |
Donate:APEX-Link | 极海半导体 陈成 |
corde format,add gitattributes | Meco Jianting Man |
demo/simulation-keil | 千帆(微信名) |
demo/stm32f103zet6/demo01-led-stm32f103zet6 | 甜航 |
demo/stm32f103zet6/demo02-led-stm32f103zet6_tworoot | 甜航 |
demo/stm32f407zgt/demo01-led-stm32f407vgt | 甜航 |
About
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. Similar project: MicroPython, JerryScript.
Resources
License
Stars
Watchers
Forks
Packages0
Languages
- C98.1%
- Assembly1.0%
- Python0.5%
- C++0.2%
- Shell0.1%
- Makefile0.1%