5 Roles for Python in Real-time Embedded Systems

Python has become quite the trending program language over the last few years. Named after the famous Monty Python comedy group, the language is object oriented and interpreted (not compiled) which has resulted in it being adopted on many platforms such as Linux, Windows, and on single board computers such as the Raspberry Pi. With such a wide and growing adoption rate, one might wonder if there is a place for Python in real-time embedded systems. Below are five roles that developers may find Python playing in real-time embedded systems.

Role #1 – Device control and debugging

During the embedded software development process, developers often find themselves analyzing bus traffic such as USB, SPI or I2C. Sometimes the analysis is simply for debugging purposes but other times there is a need to actually control the bus analyzer and send messages to the embedded system. Many bus analyzer and communication tools have user friendly interfaces that can be used to control the tool but they also normally provide a way to develop scripts that can be used to control the tool as well. Python is one scripting languages that is normally supported, sometimes exclusively, to interface with and control the tool.

Role #2 – Automating testing

The ability to control tools that can send and receive messages from an embedded system through Python opens up the possibility for using Python to create automated tests that include regression testing. Python scripts can be developed that set the embedded system into different states, set configurations and test all the possible perturbations and interactions that the system would have with the external world. One advantage to using Python for automated testing is that regression tests can be developed that constantly test and exercise the system. Any code changes that result in bugs or non-conformances will be immediately discovered.

Role #3 – Data analysis

A simple search for Python libraries on the web reveals that there are many freely available and powerful libraries to develop Python applications. Python can be used to receive critical embedded system data that can then be stored in database or locally for analysis. Developers can use Python to develop real-time visualizations that show critical parameters or store and save those parameters for later analysis. The nice part about performing data analysis using Python is that the ground work has already been done and is simply drop in.

Role #4 – Real-time Software

Python has proven itself to be so powerful and easy to use that Python is even finding its way into real-time embedded systems. Yes, the embedded software itself is being written in Python rather than C/C++. The most widely available Python version for real-time is the Micro Python port that is designed to run on microcontrollers such as the ARM Cortex-M3/4. Micro Python is not alone though. Companies such as Synapse and OpenMV are using either Micro Python or their own Python port within embedded systems. Readers interested in learning more about Micro Python might be interested in this DesignNews Continuing Education Course located here. There are also some overview articles that can be found here.  

Role #5 – Learning object oriented programming

Python is a free programming language that can be used across multiple platforms and is easy for students and non-programming types to learn how to program. The language is also modern, unlike C, and has the ability to be structured in a free-form script type manner or as a sophisticated object oriented architecture. Python has proven to be easy to learn and also very versatile. There are even instances where electrical engineers with no programming experience have been able to take Python and write useful test scripts or perform board check-outs with a minimal time investment. The learning curve isn’t steep and developers who are familiar with Python find that it is an easy language to switch. For these reasons developers shouldn’t be surprised to see Python playing a role as a programming incubator to get other engineers with less experience contributing to the design cycle sooner rather than later.

Conclusions

Students and engineers are becoming very familiar with the Python programming language. One might consider the maker movement and the Raspberry Pi to be a few reasons it has moved up the list in popularity. The language itself is flexible, easy to learn and can be adapted to work within a microcontroller based environment. Developers shouldn’t be surprised when they see Python cropping up and beginning to play a role in embedded system development.

Leave a 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.