Python on Microcontrollers

Python on Microcontrollers


Python is the most popular programming languages in the market. python is used predominantly in the Automation market, Machine Learning algorithms and other applications. Most of the engineers around the world are  programming in c, C++ on microcontrollers and what is programmed onto microcontrollers is a hex code which can be ready by the underlying processor hardware directly. So, we have an IDE for writing the program where we compile and build the code to generate a output file in hex format. We have to know what is needed for running python in microcontroller, one has to understand that Python doesn't need a compiler to create a output program unlike other programming languages like C, C++. What you do basically is create a .exe file and run it. This is basically what you do when we write small scripts using Python. Python basically needs an interpreter which generates a byte code. As discussed above, Python also has IDE like IDLE where you can write a program and execute it. There are many other IDE and some common IDE are listed below.
  • PyCharm
  • Eric
  • Komodo IDE
  • Eclipse (with PyDev Plug-in)
  • Spyder
  • PySCripter
  • Anjuta
  • KDevelop

.py is the Python file extension. We use IDE to interpret this file. Now if you want to run this file on embedded chip like a microcontroller, you need a compiler to run on the microcontroller. This compiler is a package which should have all the supporting libraries.

Proceeding further on this topic, MicroPython is a full compiler and this is what you need if you want to run Python programs on your microcontroller. MicroPython is a lean and efficient implementation of the Python 3 programming language that includes a small subset of the Python standard library and is optimized to run on microcontrollers and in constrained environments. MicroPython is packed full of advanced features such as an interactive prompt, arbitrary precision integers, closures, list comprehension, generators, exception handling and more. One of the major advantage of MPython is that it has modules such as "machine" for accessing low-level hardware.

MicroPython is written in C99 and the entire MicroPython core is available for general use under the very liberal MIT license. Most libraries and extension modules (some of which are from a third party) are also available under MIT or similar licenses. You can freely use and adapt MicroPython for personal use, in education, and in commercial products. As MicroPython is open source, the kernel can be customized and memory footprint can be reduced as per their microcontroller memory requirement. However, the features of the MicroPython shall be scaled down and is always application dependent. The power requirements for some of the application also play a crucial role which might demand a need to scale down the MicroPython.

To run a MicroPython you need the following minimum memory and clocking requirements:
  • Flash Memory - 256kB 
  • RAM - 16kB
  • Clock Frequency - 80MHz 

So, for a microcontroller to run a Python program choose a microcontroller with these memory requirements. Pyboard available in the market is the official MicroPython microcontroller board with full support for software features. Pyboard mounts STM32F405RG microcontroller which has high-speed embedded memories which are Flash memory up to 1 MB and SRAM up to 192 KB.  ESP8266 is a commonly used board for IoT applications and supports MicroPython.

Steps involved in porting MicroPython and application code on top of it.
  • Download the MicroPython source code
  • Setup the Tool Chain and the environment in the selected IDE (the IDE builds the MicroPython code)
  • Build the source code to be compatible to the selected microcontroller
  • Download the built code to microcontroller flash
  • Write the application code on top of MicroPython code for any interface level functionality
We shall discuss these steps in detail in next articles.


MicroPython is developed in the open on GitHub and the source code is available at

Visit micropython.org for more details.

Post a Comment

2 Comments

  1. Thanks for sharing like this content. I really appreciate sharing your post. and also you can go through this site and read the interesting thing Embedded design technology

    ReplyDelete
  2. Thanks for telling us about something so interesting and helpful.
    https://windowsactivators.org/komodo-ide-crack-license-key/

    ReplyDelete