Python Programming
Most embedded systems developers are used to working with low-level languages
like C and assembly. This makes sense when working with tiny microcontrollers.
Every byte counts. When it’s time for your device to communicate via the Internet,
however, programming in a language like C requires a lot of code to accomplish
even the most basic tasks. Higher-level languages like Python get the job done
with less code.
Python is useful for several reasons. Built-in data types are a definite plus. Strings, classes, dictionaries, lists, variable arrays, sets, and all the other common structures from your computer science classes are built right into the language. You don’t need to reinvent the wheel or set up and call out to a library. Another plus is that all memory allocation is automatic. This saves a lot of code and eliminates a lot of bugs!
Python has a huge library of tools available for Internet applications, text manipulation, an operating system interface, and more. The tools are debugged, documented, and ready to use. And if it isn’t in the standard library, just search for “python foobar” at Google to find a solution for foobar that somebody’s already developed. That’s how I found the serial port library I needed.
Python is portable. It runs on most common PC platforms (Windows, Mac, and Unix), so it’s easy to move your application among them.
Python is also interactive. There are no compiling or linking steps. Just run your program. Most platforms support an interactive debugger called IDLE that lets you set breakpoints, examine variables, and step through your code. The 160-line program I wrote to connect the Weasure to the UPS web site would have taken up 1,000 to 2,000 lines of code if I had implemented it in C language. That savings in source code represents a lot development time up front as well as maintenance time down the road.
There is a price for all this convenience. As an interpreted language, Python programs typically run slower than C programs, and they have the additional run-time overhead of the interpreter. However, Python gracefully supports extensions in C if you have just a few routines that are speed-critical or need low-level device access. On today’s gigahertz PC platforms, the Internet connection (or human interaction) is usually the speed-limiting factor, not the raw execution speed.
Although Python is my favorite language, other high-level languages such as Perl, Ruby, and Lisp fill the same role with varying degrees of support in different applications and platforms. If you haven’t used any of these languages, give one a try. Doing so may open up a whole new world for your device to talk to.