Python Gets Physical

By Cameron Laird and Kathryn Soraiz

Python is among the leading languages for development of embedded systems.

You probably already recognize what a temptation exaggeration is for columnists. The world is a noisy place, and when a particular story deserves readers' attention, it's easy for "three elders coincidentally die in remote village" to become "Deadly Mystery Grips Town" by the time it hits the headlines.

Embedded development, this month's Linux Developer Network theme, is important, and often misunderstood. There's no need to fudge the facts, though: Python plays a large and expanding role.

Population Size

Most of the computers in the world are embedded in a bewildering range of physical gadgets. There are hundreds of millions of conventional computers, including desktops, laptops, and servers of all sorts, installed world-wide; tens of billions of processors are embedded in the devices, appliances, and installations that surround us, though. Look, for example, at cellular handsets: there are at least two billion of them in use worldwide (also see this).

Python is a handy language for programming many of them, handier than you might realize. Nokia is the leading handset manufacturer worldwide, with nearly 40% of the global market, and an installed base of half a billion programmable devices. Nokia officially promotes Python for its S60 platform to the nearly four million (!) Nokia mobile developers--not employees, but third-parties with enough motivation to register for the Forum Nokia support program.

Note that Google's Android has a limited amount to teach us about embedded Python programming, at least to this point. While Google certainly makes plenty of use of Python, even in some of the tools around Android, we've not come across anyone successfully programming Android itself with Python, nor have we tried it ourselves. Among the slickest connections to Android, though, is Jeffrey Sharkey's Amarok remote control, whose desktop side he coded in Python. Note the use made there of DCOP, and anticipation of D-Bus; these are technologies future installments of Regular Expressions will investigate in more detail.

Chips and Wires and Waves

Python also has an encouraging history in more traditional embedded development. Carmanah Technologies Corporation, for instance, began to experiment with Python during development of a sophisticated crosswalk traffic beacon, and now uses Python throughout its engineering.

Cliff Brake wrote a thoughtful article a couple of years ago on his use of Python on a 130 MHz ARM-Linux processor that, among other things, provided a maintainable Web server in a device. As he summarizes on his corporate site, "... you can get [when ordering runs of a thousand pieces] a processor, RAM, and flash that is more than capable of running Linux for about $20."

Several toolsets aimed at embedded development feature Python. Digi International sells about $50 million annually of networking products; its Drop-in Networking line "incorporates a Python development environment into each ConnectPort X gateway."

What's In It for You? Winning Teamwork

The cases above make it clear that Python has a role in embedded development in the world at large; the real question, of course, is whether it should have one in the embedded Linux programming you do.

Yes, most likely, it should, and for a specific reason only implicit in the remarks above: Python promotes better teamwork.

Python's aptness for group work was what most caught our eye, in fact, when we first wrote about the language over ten years ago. Think about how this applies in embedded development: even more than with conventional application programming, embedded projects are likely to involve heterogeneous teams. Your daily communications are likelier to be with a radio or chemical engineer, than other programmers. Practitioners in other domains have plenty of experience with C and Basic, the languages most likely to be available for embedded work. As a crude generalization, they think they're better with C and Basic than the actual production code we've encountered. Python, however, is simultaneously more expressive, more readable, and safer than either of these, in our experience. Python is widely recognized as "executable pseudocode". Engineers working with Python are at less risk to leak memory, violate array bounds, mis-structure their code, and so on, in comparison to their output when writing C.

Intelligent professionals whose specialty is not programming too often have to focus on the language when they work in C and Basic--and their Java is far from pretty. Python fits so well, though, that even people whose full-time attention is something other than programming seem comfortable with it: they think about the problem, rather than the language.

The same argument applies even if you are nominally doing all the programming. Your teammates will be able to read your Python source for its circuits or materials content in a way they never would when you write C or Java. This is a healthy thing, one whose power is difficult to explain until you've experienced it for yourself.

Another aspect of this same dynamic recognizes how much of embedded programming involves configuration. Embedded engineering typically involves sensitivity to different costs than we experience in desktop programming; it's a big win to be able to experiment in software with configuration variations. Python and other scripting languages are perfect for configuration tasks, and encourage productive experimentation in a way C never will.

Next Steps

One of our aims with each column is to provide at least one fragment of working code; concrete examples are enormously valuable. A movie review which includes a clip of Jean Reno in action can be far clearer than one which confines itself to words about his technique.

There's a challenge in explaining embedded Python, though, for essentially all our own work is encumbered by non-disclosure agreements. We co-sponsor the Agile Control Forum (ACF) to promote sharing in this area; note that the "Control" here refers to "process control", a broad term we use to cover a range of factory automation, transportation systems, robotics, and related embedded applications. While the ACF is generally so quiet as to be misleading about how much work is actually done in this area, it's a good starting point for those who want to read more. Even better, if you have ideas of your own for connecting Python to the physical world, any contributions to ACF will have eager readers.

At mid-month, we'll be back to look at one particular instrumentation project, and how it takes advantage of a high-level language.

Kathryn and Cameron run their own consultancy, Phaseit, Inc., specializing in high-reliability and high-performance applications managed by high-level languages. They write about high-level languages and related topics in their "Regular Expressions" columns.

 

0
Copyright © 2008 Linux Foundation. All rights reserved.
LSB is a trademark of the Linux Foundation. Linux is a registered trademark of Linus Torvalds