5 Advantages of Using Micro Python for Embedded Software Programming

Jacob Beningo

October 12, 2015

4 Min Read
5 Advantages of Using Micro Python for Embedded Software Programming

A few years ago, Damien George successfully funded a Kickstarter project that launched Micro Python, a “lean and fast implementation of Python 3,” designed to run on microcontrollers. In an article on Design News’ sister publication EDN.com, I discussed the background of the language and the ARM Cortex-M hardware on which it is designed to run. Here, let’s examine five advantages of using Micro Python for embedded software that are difficult or nearly impossible with C.

MicroPython.png

1.) Human-Readable Language

Any developer who has written a line of C code knows that the programming language can produce some of the most cryptic software ever developed. Entire competitions are devoted to writing programs that are obfuscated and impossible to comprehend. Python is different. Developed with readability in mind, Python is easy to read, is 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.

2.) Built-In Exception- and Error-Handling

The C programming language has no exception- and error-handling. Embedded system developers are thus stuck having to create their own exception- and error-handling solutions. Micro Python, though, 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 not noticing a thing.

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.

MORE ARTICLES BY JACOB BENINGO:

4.) Object Oriented Language

Using Micro Python fills in a number of gaps in the C programming language, 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.

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 on the workings of the low-lying hardware.

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 Internet of Things or consumer electronics products. The language port has only just stepped onto the stage, and only time will tell whether it will gain widespread adoption or gain a cult following in isolated circles.

Going Further

1) Check out the Micro Python website and documentation here.

2) I am putting together a series of videos on Micro Python that can be seen on my YouTube channel.

Design-and-Manufacturing-Philly-and-Texas.png

Jacob Beningo is a Certified Software Development Professional (CSDP) whose expertise is in embedded software. He works with companies to decrease costs and time to market while maintaining a quality and robust product. Feel free to contact him at [email protected], at his website www.beningo.com, and sign up for his monthly Embedded Bytes Newsletter here.

About the Author(s)

Jacob Beningo

Jacob Beningo is an embedded software consultant who currently works with clients in more than a dozen countries to dramatically transform their businesses by improving product quality, cost and time to market. He has published more than 300 articles on embedded software development techniques, has published several books, is a sought-after speaker and technical trainer and holds three degrees which include a Masters of Engineering from the University of Michigan.

Sign up for the Design News Daily newsletter.

You May Also Like