Micro Python is an implementation of the Python programming language, written from scratch and optimized to run on micro-controllers such as the ones based on ARM Cortex-M cores. Damien George, the developer, also designed the Micro Python board powered by STMicro STM32F405 Cortex M4 MCU for the purpose of running Micro Python.
- MCU – STMicro STM32F405RG @ 168MHz with 1MB flash, 192KB RAM, and an FPU.
- External storage – Micro SD slot
- 30 general purpose I/O pins – 5 USARTs, 2SPIs, 2 I2C busses, 14 ADC pins, 2 DAC pins, 2CANs, and 4 servo ports with power.
- Built-in USB interface
- Misc – 4 LEDs, a user switch, a reset switch, a real-time clock, and a 3-axis accelerometer (MMA7660)
- Dimensions – 33×40 mm
The USB interface acts both as a serial device (CDC VCP) and removable storage device (MSC) to respectively access the Python terminal & debugging, and copy Python scripts to the board. The USB port can also be used to flash Micro Python onto the micro-controller.
Micro Python will handle the low level talks to boot the board, run ./boot.py to configure USB and other low level parameters, and will look for and launch your main program located by default in ./src/main.py. All you need is a Windows, Mac or Linux computer, connect the board via USB, and copy your Python scripts to the board, which just looks like another USB flash drive from your computer point of view.
Here are some code snippets:
- Blinking LEDs every second:
- Reading accelerometer values:
Shell12accel = pyb.mma() #Read accelometer valuesprint(accel) #Print x-axis value
- Controlling servos:
Shell12pyb.servo(1,45) #Set servo 1 to 45 degreespyb.servo(2,90) #Set servo 2 to 90 degrees
Micro Python has the following key features:
- Python 3.3 grammar and semantics. Libraries not all available.
- Support for 32-bit ARM processors with the Thumb v2 instruction set, e.g. ARM Cortex-M.
- Space-optimized binary compiled to Thumb v2 machine code: around 60KB
- Size of all code, including FAT support, SD card, USB serial, USB mass storage, USB HID, Bluetooth, LCD, servo, timer: about 110KB.
- RAM – “Hello World”: 4KB.
- 4 types of code emitters – (compressed) byte code, native code, native code with native types, and inline assembler.
Damien George is taking the project to Kickstarter in order to complete the development of Micro Python, make it open source (MIT License), and fund mass production for the Micro Python board, which will also be Open Source Hardware. If you just want to support his development efforts, and get early access to the source code and updates, you can pledge 10 GBP (~$16 US). You’ll have to pledge 24 GBP (~$39 US) in order to receive Micro Python board as well, adding 4 GBP if you live outside the UK. There are also some other pledges with kits (Robotics, Wireless, etc…). The project already reached its funding target, and delivery is expected in March 2014.
I’ve also discovered another Python implementation for MCU called PyMite (aka p14p, python-on-a-chip) via the Kickstarter FAQ. Damien explains Micro Python does not allocate heap memory for integer operations and method calls, and by doing so, reduces the risk of inducing a garbage collection cycle which would cause performance issues during critical code, e.g. interrupt subroutines.