articles

Running Python on a Microcontroller With only 240kB Memory Footprint!

Monday, May 30, 2016

What is not to love about Python?

Don't get me wrong. C language is also easy to learn and it's definitely not as tedious to learn as Assemby language, which is another low level programming language. In fact, if you are looking to learn a programming language for the first time, the Arduino language is probably the easiest programming language to learn for beginners. The Arduino language is basically a simplification of C/C++ so you can virtually copy Arduino code to a C/C++ file and it will work.

With that said, if you have programmed in both C language and Python language before, you will know how much quicker it is to implement code and debug using Python. No compilation is needed so code can be executed directly "on the fly". You can literary program and quickly prototype an embedded system with Python in minutes because of how much simpler and smaller Python code is.
However, when it comes to programming microcontrollers using Python the Achilles heel has always been high memory consumption and no access to low level. Programming a microcontroller using Python uses huge amounts of memory and microcontrollers typically have memory ranging between 16K and 256 KB.

The C language has been the go-to programming language for programming micro controllers for quite sometime now and it's not surprising since you get plenty of memory, low level access and speed efficiency when programming a microcontroller using C language.

Having said this, if you're a die-hard fan of Python and love programming using the Python language you're going to love programming in Python even more thanks to up and coming solutions such as Micro Python!
MicroPython pyboard next to Raspberry Pi and Arduino

Micro Python allows you to run Python on microcontrollers with minimal RAM usage (as little as 192kB!) and you can easily write high level code for the brains of a robot using Micro Python, as well as blink LEDs, read voltages, and move servo motors.

What makes Micro Python especial is that it is a compact python compiler that uses memory more efficiently by compiling functions according to speed, memory use and functionality (and it also includes an inline assembler).
Micro Python has somewhat become the holy grail for rapid prototyping programming because of its powerful STM32F405 microcontroller and useful I/O (a total of 30 input/output pins).

Micro Python +Python  works on Linux +Linux, Windows, Mac and programming is done via any text editor. Also, it can run with or without a PC. When connected to a PC via USB cable, it acts like a USB flash drive, allowing you to copy python scripts across like you normally would, and when the board reboots it runs the scripts.

Micro Python is designed to run on microcontroller boards such as Espruino Pico, Arduino Mega (via Pymite), WiPy, Pyboard and the Linux-based Arduino Yun which can also run Python code thanks to its AVR chip and MIPS chip. You can also run Micro Python on other microcontroller boards.

You Might Also Like

0 comments

About Gadget Explained

Connect With Gadget Explained