Python’s Big Push into the Embedded Space

Python’s Big Push into the Embedded Space

Python is very popular in many areas from machine learning to powering websites, but it’s also great for embedded applications.

C and C++ continue to dominate programming languages for embedded applications. However, they have lots of competition from alternatives like Javascript and Python. The latter is very popular for driving websites, where it competes with languages like PHP. Stack Overflow’s 2017 survey highlights Python’s growth in popularity (Fig. 1), evidenced by its use and support across the board from embedded to enterprise development.

1. Stack Overflow found that interest in Python has steadily grown. (Courtesy of Stack Overflow)

Python has garnered a significant chunk of support in the machine-learning space, where it can be used with platforms like Caffe and TensorFlow. BrainChip’s Akida development environment uses Python for spiking neural networks.

The Python Software Foundation is the keeper of the Python keys. Open-source versions of Python can be downloaded for a range of platforms, including Linux and Windows. Numerous integrated development environments (IDEs) exist for Python as well, including multiplatform tools like Eclipse (PyDev) and Microsoft’s Visual Studio.

Python has been popular as an embedded scripting language for everything from debuggers to CAD applications. Autodesk’s 3D animation program, Maya, can be programmed in Python. Likewise, one of its competitors, Blender, is also programmed using Python. Python is even supported by the Robot Operating System (ROS).

VDC Research has seen growth in the use of Javascript and Python in IoT devices. “The embedded engineering community is embracing the use of scripting languages,” says Chris Rommel, EVP of IoT & Embedded Technology research at VDC. “What began primarily isolated as a tool in the QA domain has quickly expanded within the software development ranks, with Python, in particular, showing incredible growth in the past few years.”

Python tends to be implemented as an interpretive scripting language, although implementation is akin to Java where just-in-time (JIT) compilation is used for performance reasons. There are native code Python compilers such as PyPy and Cython. Compact implementations are designed for microcontrollers such as MicroPython, which is designed for bare-metal applications requiring only 256 kB of code space and 16 kB of RAM. Pyboards, available from a number of sources, are designed to host MicroPython. A typical pyboard runs an STMicroelectronics STM32F4.

2. Zerynth is a Python platform designed to link compact IoT platforms to the cloud.

Several development platforms specifically target embedded applications and the Internet of Things (IoT), such as Zerynth (Fig. 2). It targets 32-bit microcontroller platforms and is designed to easily mix with C/C++ code.

Zerynth middleware links to cloud services like Microsoft Azure, Amazon Web Services. IBM Bluemix, Ubidots, Google Cloud Platform, and The Things Network. “Our mission is to help speed up projects and development for the IoT by reducing complexity and removing the barriers to entry for engineers,” says Gabriele Montelisciani, CEO at Zerynth.

Zerynth Studio is a cross-platform IDE that targets the Zerynth Virtual Machine, which has a tiny footprint. It runs in as little as 60 kB of code and 3 kB of RAM. Its built-in multithreaded RTOS is designed to support Python and C. A hardware-abstraction layer allows for application portability across a range of processing platforms.

Python Graphics and User Interfaces

A plethora of graphics and user-interface options come with Python. Many of these are applicable to embedded applications and a number come out of the scientific community. The Matplotlib is a 2D plotting library that provides a MATLAB-style interface.

Developers can take advantage of the open-source Kivy framework. It runs on a range of platforms including Linux, Windows, OS X, Android, iOS, and the Raspberry Pi.

The Qt Company released its latest Qt for Python (Fig. 3), also known at Pyside2, at this year’s SIGGRAPH. Qt is a popular user-interface framework that’s been around for over 25 years. C, C++, Javascript and now Python have all been used with Qt. It can handle graphics and all sorts of multimedia formats as well as work with radios and cameras. The Qt Creator application generates definitions that are usable with any programming language.

3. Qt for Python brings the Qt graphical framework to Python developers, including design tools like Qt Creator.

The framework runs on everything from microcontrollers to the web. It’s designed to be lightweight while providing features like internationalization support. There’s even state machine support. Furthermore, it has its own declarative user-interface markup language called QML.

Why Use Python for Embedded Programming?

Python has many advantages, including support for multiple programming paradigms while supporting readable and maintainable code. It uses indentation and eliminates the need for brackets common to languages like C, C++, and Java. Its interactive nature enables a test-driven development approach.

Probably the most important reasons for using Python is its extensive collection of support libraries and the fact that it’s been incorporated into numerous applications like Maya.

Its dynamic nature is both a blessing and a curse. Many problems can only be found by running the application. At the opposite end of the spectrum would be the SPARK language, a provable subset of Ada. In the middle reside languages like C and C++, although C’s type system is very limited.

Speed often crops up in a discussion about Python and other languages when comparing them to C and C++. This type of performance can be important for some applications, but Python is typically fast enough even on microcontrollers for most applications.

Python does use a garbage collector like Java. Though it can affect a designer’s choice, the advantage of system-managed memory can be significant.

Also, some implementations of Python use a global interpreter lock (GIL). GIL can affect multithreaded performance. Implementations like the .NET-based IronPython and the Java-based Jython are examples that don’t employ a GIL and handle multithreading on their own terms.

Python isn’t a fit for all embedded applications. Nonetheless, quite a few can benefit from Python’s dynamic nature, flexibility, and extensive support.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.