Blog

PikaScript - A lightweight Python implementation that runs on STM32 and other low-end MCUs - CNX Software

CNX Software – Embedded Systems News

Reviews, tutorials and the latest news about embedded systems, IoT, open-source hardware, SBC's, microcontrollers, processors, and more STM32F031G4U6

PikaScript is an ultra-lightweight Python engine that can run on microcontrollers with as little as 4KB of RAM and 32KB of Flash, while the more popular MicroPython requires at least 256kB of code space and 16kB of RAM.

PikaScript was initially developed to run on STM32G030C8 and STM32F103C8 MCUs, meaning, for example, it works on the BluePill board, but it has also been ported to other platforms like WCH CH582 RISC-V MCU, WinnerMicro W806 C-Sky microcontroller, as well as other like Raspberry Pi RP2040, ESP32-C3, etc… but those are not quite as well supported with some features missing.

PikaScript also permits the binding C function to a Python module through Pika Pre-compiler. PikaScript can run bare metal on the microcontroller, but also supports real-time operating systems such as RT-Thread and VSF (Versaloon Software Framework), as well as Linux. Just like MicroPython, it’s using a subset of Python 3, but I’d assume with even fewer features due to the smaller footprint.

Pika-Pi-Zero is the official board for the project, but I can only find it on Taobao at this time. It is based on STM32G030C8T6/STM32G070CBT6 MCU. It’s possible to generate a default project for your hardware target and operating system through an online tool.

You’ll also find the source directly on Github together with documentation on some samples (GPIO, USART, ADC, PWM output, RGB display, and Snake game demo).  We’re told the maximum RAM usage of these demos is only 3.56KB or 4.56KB if the 1KB stack is included, while the maximum storage usage is 30.4KB. If we take STM32F103C8T6 microcontroller with 20KB RAM and 64KB flash for reference, that means less than 25% RAM and less than 50% Flash are used by PikaScript firmware and sample code.

If you’d like more details and/or ask questions, Lyon, one of the PikaScript developers, will also give a talk entitled  “PikaScript – An Ultra-lightweight Python Engine Under RT-Thread” at the 2022 RT-Thread IoT OS Global Tech Conference taking place on June 1-3 online.

Jean-Luc started CNX Software in 2010 as a part-time endeavor, before quitting his job as a software engineering manager, and starting to write daily news, and reviews full time later in 2011.

Support CNX Software! Donate via cryptocurrencies or become a Patron on Patreon

BQ25601RTWR Change Ad Consent Do not sell my data