https://github.com/pikasTech/pikascript Skip to content Sign up * Product + Features + Mobile + Actions + Codespaces + Packages + Security + Code review + Issues + Integrations + GitHub Sponsors + Customer stories * Team * Enterprise * Explore + Explore GitHub + Learn and contribute + Topics + Collections + Trending + Learning Lab + Open source guides + Connect with others + The ReadME Project + Events + Community forum + GitHub Education + GitHub Stars program * Marketplace * Pricing + Plans + Compare plans + Contact Sales + Education [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} pikasTech / pikascript Public * Notifications * Fork 26 * Star 440 An ultra-lightweight Python engine that can run with 4KB of RAM and 32KB of Flash (such as STM32G030C8 and STM32F103C8), and is very easy to deploy and expand. pikascript.com/ License MIT license 440 stars 26 forks Star Notifications * Code * Issues 8 * Pull requests 0 * Discussions * Actions * Projects 0 * Wiki * Security * Insights More * Code * Issues * Pull requests * Discussions * Actions * Projects * Wiki * Security * Insights This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. master Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags 2 branches 24 tags Code Latest commit @pikasTech pikasTech fix 'from PikaObj import *' error info ... aaffdba May 19, 2022 fix 'from PikaObj import *' error info aaffdba Git stats * 3,482 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .github/workflows add wine32 to docker May 4, 2022 bsp fix 'from PikaObj import *' error info May 19, 2022 docker add rust_config May 5, 2022 document redirect document link Mar 31, 2022 examples remove from PikaObj import * in main.py May 19, 2022 package assert for test_import_bf1/2 is ok Apr 28, 2022 port fix 'from PikaObj import *' error info May 19, 2022 src fix 'from PikaObj import *' error info May 19, 2022 tools fix 'from PikaObj import *' error info May 19, 2022 .gitattributes Update .gitattributes Sep 26, 2021 .gitignore ignore build for port/linux Oct 5, 2021 LICENSE fix typo in license Mar 27, 2022 README.md update README.md. May 6, 2022 README_zh.md update README_zh.md. May 6, 2022 SConscript Update SConscript Dec 7, 2021 _config.yml Set theme jekyll-theme-slate Jan 3, 2022 logo.txt logo Nov 25, 2021 packages.toml update v1.8.0 for rtThread port May 17, 2022 View code [ ] PikaScript Cross platform ultra lightweight embedded Python engine 1. Abstract [(Video)] PikaScript hand by hand Get PikaScript: Use Online Project Generator Use Pika package manager PikaPackage.exe Quick Start Document Folders 2.Platform support MCU support Board support OS support Related Projects PikaScript Bluepill Demo In PlatformIO -- Python-like REPL 3.Characteristic (1)Run environment (2)Develop enviroment (3)Syntax Operator Control flow (4)Develop standard. 4.Both talk and show the code: Telegram E-mail: liang6516@outlook.com Tencent QQ: 645275593 5.Demo Demo 01 GPIO Demo 02 USART Demo 03 ADC Demo 04 PWM output Demo 05 RGB Demo 06 Snake (Need LCD) RAM resource comparison Flash Resource Comparison Reference price comparison (take the selling price of 10 pieces in Lichuang Mall on September 11, 2021 as reference) About the custom extern module ? Boxes~ Rotating suns~ 6.Test and develop Core Test core in docker (recommend) Test core in linux (ubuntu20.04 is recommend) 7.Contribute README.md logo PikaScript Cross platform ultra lightweight embedded Python engine [6874747073] [6874747073] [6874747073] [6874747073] [6874747073] [6874747073] [6874747073] [badge] Zhong Wen Ye | Forum | Documents | Videos | BSP | Package Manager | RT-Thread package | Contribute | Business image 1. Abstract PikaScript is an ultra-lightweight Python engine with zero dependencies and zero-configuration, that can run with 4KB of RAM and 32KB of flash (such as STM32G030C8 and STM32F103C8). [147799704-d79345da-a2b9-4593-b1eb-ff9de127429a] 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 .py and the bindings are autoly generated by Pre-compiler. [138021445-13643518-b0a3-4872-a290-5dec27697837] [(Video)] PikaScript hand by hand Get PikaScript: Use Online Project Generator Generator url: http://pikascript.com [152632673-019a7f92-7b7f-4fb5-92b7-4ae4c26ec865] Use Pika package manager PikaPackage.exe 1. Run the PikaPackage.exe directly, then the pikascript 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 modules:packages.toml Quick Start You can use simulation project to quick start without hardware,or 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 PikaScript 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. Document https://pikadoc.readthedocs.io/en/latest/index.html Folders src - core code bsp - mcu/board support port - OS support 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 uart pwm adc i2c stm32g030c8 [?] [?] [?] [?] [?] [?] stm32g070cB [?] [?] [?] [?] [?] [?] stm32f103c8 [?] [?] [?] [?] [?] [?] stm32f103rb [?] [?] [?] [?] [?] [?] stm32f103ze [?] [?] [?] [?] [?] [?] stm32f103rc [?] [?] [?] [?] [?] [?] stm32f401cc [?] [?] [?] [?] [?] [?] stm32f411ce [?] [?] [?] [?] [?] [?] stm32f407ze [?] stm32f407zg [?] stm32h750vb [?] stm32f051r8 [?] ch582 [?] [?] [?] [?] [?] ch32v103r8t6 [?] [?] cm32m101a [?] w801 [?] w806 [?] [?] [?] [?] [?] [?] apm32f030r8 [?] apm32e103vb [?] bl-706 [?] Raspberry Pico [?] ESP32C3 [?] TC264D [?] devc [?] Board support Board bsp gpio uart pwm adc i2c rgb lcd arm-2d Pika-Pi-Zero [?] [?] [?] [?] [?] [?] [?] [?] [?] 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 [?] [?] [?] Related Projects PikaScript Bluepill Demo In PlatformIO -- Python-like REPL https://github.com/maxgerhardt/pikascript-pio-bluepill 3.Characteristic (1)Run environment Support run in mcu without OS or file system. Can run in everywhere with RAM >= 4kB and FLASH >= 32kB,such as stm32g030, stm32f103c8t6, esp8266. (2)Develop enviroment Support run and program python scripts by serial. Wei Xin Jiao Liu Qun 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 compile time - Based on Pika Pre-compiler. Support method invoke, argument define, new object, free object, control flow(if\while) and operator ( + - * / < == > ). - Based on Pika Runtime Core. 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 += -= *= /= [?] [?] [?] [?] [?] [?] [?] [?] [?] [?] [?] [?] [?] [?] [?] [?] [?] [?] [?] [?] [?] [?] [?] Control flow if while for else elif break continue [?] [?] [?] [?] [?] [?] [?] (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: Telegram tg https://t.me/+JL3TZ9k-Lfg2OWE1 E-mail: liang6516@outlook.com Tencent QQ: 645275593 5.Demo The scripts in demos are in the examples folder. Demo 01 GPIO import PikaStdLib import STM32G0 mem = PikaStdLib.MemChecker() io1 = STM32G0.GPIO() time = STM32G0.Time() io1.init() io1.setPin('PA8') io1.setMode('out') io1.enable() io1.low() print('hello pikascript') 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 import PikaStdLib import STM32G0 time = STM32G0.Time() uart = STM32G0.UART() uart.init() 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 import PikaStdLib import STM32G0 time = STM32G0.Time() adc1 = STM32G0.ADC() adc1.init() adc1.setPin('PA1') adc1.enable() while True: val = adc1.read() print('adc1 value:') print(val) time.sleep_ms(500) mmexport1631351523907 Demo 04 PWM output 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) Demo 05 RGB 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) 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 image 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 chip STM32F405RG and the PikaScript chip STM32G070CB. RAM resource comparison image Flash Resource Comparison image Reference price comparison (take the selling price of 10 pieces in Lichuang Mall on September 11, 2021 as reference) image 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) Rotating suns~ Hnet-image (6) 6.Test and develop Core Test core in docker (recommend) step1: Clone the repo git clone https://github.com/pikastech/pikascript cd pikascript/docker step2: build and run the docker contianer sh build.sh sh run.sh # now you are in the port/linux step3: init the port/linux sh pull-core.sh sh init.sh step4: test the core sh gtest.sh sh ci_benchmark.sh step5: Run the REPL sh run.sh Test core in linux (ubuntu20.04 is recommend) step1: Clone the repo git clone https://github.com/pikastech/pikascript cd pikascript/port/linux step2: install dependency sh install_dependency.sh # install dependency step3: init the port/linux sh pull-core.sh sh init.sh step4: test the core sh gtest.sh sh ci_benchmark.sh step5: Run the REPL sh run.sh 7.Contribute Content Contributer Donate:500Y= (ctypes Xiang Guan ) Jiang Tai Ping fix linux install script Maximilian Gerhardt ch582 package Meng Cheng MI ch582 BSP Meng Cheng MI Donate:EC600X QuecPython Kai Fa Ban Yi Yuan Tong Xin Wu Jia Yu Performance Point: 900->1400 GorgonMeducer stm32f051r8 BSP unsigned stm32f407ze BSP unsigned devc BSP unsigned TC264D BSP unsigned PikaVM improvement GorgonMeducer W801Device package Liu Yan (Wei Xin Ming ) W806 bsp Liu Yan (Wei Xin Ming ) Donate:ESP32C3 5pic,Diao Shi Qi Qi Ming Yun Duan Cang Yu Donate:LS1C101Xin Pian 10pic, LS1c101Kai Fa Ban ,Diao Shi Qi Long Xin Ju Le Bu Shi Nan PikaVSF OS package versaloon ESP32C3 BSP Cang Yu Donate:ESP32Kai Fa Ban , Mo Shui Ping *4 name(Wei Xin Ming ) Donate:Zhi Long Kai Fa Ban Long Xin Ju Le Bu Shi Nan package/STM32F1 sjy package/STM32F103RBBooter sjy bsp/stm32f103rb sjy Ji Yu QEMUDe ARM-2DFang Zhen Gong Cheng liuduanfei Donate:GD32E103TBXin Pian 2Pian Xin Xi Niu (Wei Xin Ming ) Rt-thread Zhi Chi Bao , Gua Pei Ceng , Mo Kuai Meco Jianting Man Donate:Yi Yuan EC600S-CN 4GMo Kuai Yi Yuan Mo Kuai Donate:Bo Liu BL706 Kai Fa Ban Bo Liu Zhi Neng bouffalolab Donate:Zhong Guo Yi Dong CM32M101A Kai Fa Ban Meng Wei (Wei Xin Ming ) Donate:APM32F030R8 Kai Fa Ban Ji Hai Ban Dao Ti Chen Cheng Donate:APM32E103VB Kai Fa Ban Ji Hai Ban Dao Ti Chen Cheng Donate:APEX-LinkFang Zhen Qi Ji Hai Ban Dao Ti Chen Cheng Yuan Ma Ge Shi Hua ,Zeng Jia gitShu Xing Wen Jian Meco Jianting Man demo/simulation-keil Qian Fan (Wei Xin Ming ) demo/stm32f103zet6/demo01-led-stm32f103zet6 Tian Hang demo/stm32f103zet6/ Tian Hang demo02-led-stm32f103zet6_tworoot demo/stm32f407zgt/demo01-led-stm32f407vgt Tian Hang About An ultra-lightweight Python engine that can run with 4KB of RAM and 32KB of Flash (such as STM32G030C8 and STM32F103C8), and is very easy to deploy and expand. pikascript.com/ Topics python language iot esp8266 microcontroller embedded lua micropython esp32 stm32 mcu rtthread luatos Resources Readme License MIT license Stars 440 stars Watchers 10 watching Forks 26 forks Releases 23 v1.8.0 Latest May 16, 2022 + 22 releases Packages 0 No packages published Contributors 7 * @pikasTech * @liang6516 * @mysterywolf * @GorgonMeducer * @dreamcmi * @maxgerhardt Languages * C 97.7% * Assembly 1.3% * Python 0.4% * C++ 0.3% * Shell 0.2% * Makefile 0.1% * (c) 2022 GitHub, Inc. * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.