5 Advantages of using Micro Python for Embedded Software

A few years ago, in December of 2013, Damien George successfully funded a Kickstarter project that launched Micro Python. Micro Python is a “lean and fast implementation of Python 3” designed to run on microcontrollers. In an article on EDN.com entitled “Real-time Software using Micro Python”, I discussed the background of the language and the ARM Cortex-M hardware that it is designed to run on. In this article, let’s examine five advantages of using Micro Python for embedded software that C makes difficult or nearly impossible.

Advantage #1 – Human readable language

Any developer who has written a line of C code knows that the C programming language can produce some of the most cryptic software ever developed by the human race. Entire competitions are devoted to writing programs that are obfuscated and impossible to comprehend. Python is different. Python was developed with readability in mind. Python is easy to read, easy to write and has a low learning curve compared to other languages. A scaled version of Python in the form of Micro Python for microcontrollers opens possibilities for rapid prototyping and opportunities for improving code maintenance and portability.

Advantage #2 – Exception and Error Handling Built-in

The C programming language has no exception and error handling. Developers of an embedded system are therefore stuck having to develop their own exception and error handling solutions. Micro Python on the other hand includes and extends the exception and error handling of Python. The default behavior of Micro Python is to stop program execution when an error is encountered, printing out the file and line number so that a developer can easily spot the problem.

The default exception and error handling of Micro Python is easily overridden with the use of try/except and try/except/finally blocks. Just like in a higher level language, surround a block with a try/except block and if an exception occurs it can be caught and dealt with accordingly. The script will continue to run, handling the exception with the user hopefully not noticing a thing.

Advantage #3 – Open source and free

Micro Python is open source and uses the MIT software license which means it can be used and abused in any manner the developer deems appropriate. Development teams can take the latest release and run with it. Want a larger or smaller processor, simply port Micro Python to that microcontroller. The primary tree provides examples for a number of different processors and configurations. Improvements can be shared with the community and merged back into the main trunk, if the development team feels like sharing of course. The advantage is that obtaining and porting Micro Python is free and requires very little time investments.

Advantage #4 – Object Oriented Language

Using Micro Python fills in a number of gaps that the C programming language is lacking including the ability to create classes and use object oriented programming techniques. Embedded software developers using Micro Python can take advantage of modern day programming constructs such as inheritance and polymorphism. Encapsulation and information hiding can be easily implemented without much effort. Some would argue these same constructs can be produced in the C language, which dates back to 1972, but the fact is the amount of time and effort required makes this argument laughable and the implementations highly error prone.

Advantage #5 – Abstracts out the hardware layer

Micro Python abstracts out the details for the underlying microcontroller hardware. Instead of worrying about the bits and the bytes, a developer simply accesses methods of a peripheral object to control the hardware. Hardware control is done through a specialized pyb library. To control an LED, a developer only needs to create an object initialized with the LED pin information and then turning the LED on or off becomes a trivial exercise of accessing the on and off methods of the object. The abstraction of the hardware layer allows an engineer to focus on the application specifics rather than how the low lying hardware works.

Final Thoughts

Micro Python is an interesting language for use in embedded software and may provide developers with a new tool in which to rapid prototype an embedded system. Micro Python could even provide a shorter development path for IoT or consumer electronics products. The language port has only just stepped onto the stage and only time will tell whether it will gain wide spread adoption or gain a cult following in isolated circles.

Share >

5 thoughts on “5 Advantages of using Micro Python for Embedded Software

  1. I agree to all the disadvantages C brings with it and I also agree to the advantages of Python. But why compare Micro Python with C and not with C++? Nowadays, C++ is used widely, even in embedded systems. I guess, the only advantage Micro Python has left in such a comparison would be the better readability.
    Further, someone has to write the hardware objects, especially in embedded systems where you often change the underlying hardware and you can seldom expect the SoC manufacturer to provide code snippets for accessing the actual hardware even in C language, not to speak of Micro Python.

    • 80% of embedded systems are still written using C. Every SoC or microcontroller provider develop their SDK’s in C not C++. A comparison between MicroPython and C make much more sense for the general community. Thanks for the comments!

  2. Wondering why every SoC or mcu provider develop their sdk in C and not C++. I believe Arduino would definitely not be so successful if C is used instead of C++. C++ makes a huge difference.

    • I’m not sure why C is always preferred. I’ve known vendors who launched a new platform, did it in C and then created C++ like features like “this”. I think they see they industry survey results that 80% of systems use C and they are afraid to lose out on market share for using C++.

      • May be it is time for the vendors to change?
        We don’t need all the advanced features of C++ for microcontrollers.
        The C++ for ATMega328 is already great.
        The codes can be re-used in any platform supporting C++.
        After enjoying using C++, I never want to work in platforms that only support C.

        One great disadvantage of using C/C++ is the time take to build the application and upload to the target board.
        Micropython is fast!

Leave a Reply to wongss Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.