Parallel Programming: Plumbing on Arduino

In real life, all sorts of things happen at the same time: the milk truck eases into your space, and somebody screams somewhere… But in programming, how do you chew gum and walk at the same time?

Today’s microprocessors—including the ATMEGA processors that power the Arduino—run by executing a linear stream of commands very, very quickly. The illusion of concurrency can be created and maintained if the processor is fast enough to make one action seem as though it is done at the same time, even if they are only one microsecond apart. Even so, there is a problem with the C/C++ language that the Arduino development environment uses when you want to manage concurrency.

Take this example: you want to blink a red LED on and off every 500 ms, and at the same time you want to blink a green LED on and off every 250 ms. The delay() function cannot be used, because delays basically put the processor into zombie mode, disabling it from receiving or sending any information. There are Arduino libraries available that can help the programmer with timing to juggle multiple actions, such as Metro, but they are wordy solutions, hamstrung by the linear nature of C itself.

Enter Plumbing, an Arduino interactive development environment which specializes in its ability to conceptualize and implement parallel programming. Plumbing is adapted from the language called occam-π (occam-pi). Occam-π, together with the Transterpreter (which allows Occam-π to be run on small microcontrollers like the AVR ATMEGA chips), runs on an open-sourced Java-based development toolchain.

Throughout the setup process, I referred to an excellent introductory book called Plumbing for the Arduino, by Matthew Jadud, Christian Jacobsen and Adam Sampson, freely available as a downloadable PDF file.

A short demonstration program

Setting up an Arduino Duemilanove for Plumbing is relatively straightforward. You need to install the latest JAVA distribution, which is available for all major operating systems. The Plumbing IDE is available for Mac, Windows or Ubuntu Linux, but since the dual-boot netbook I use for my development machine uses Ubuntu 10.10 (Maverick Meerkat), and Plumbing hasn’t caught up, I felt compelled to switch over to Windows XP.

Programming using Plumbing/occam-π on the Arduino is made possible when you upload the Transterpreter firmware into the Arduino. Nothing permanent is done to your Arduino unit in the process, because the firmware is really, in the words of the authors of Plumbing for the Arduino, just an overgrown Arduino sketch. So if you want to go back to Wiring, the conventional Arduino development environment, there’s nothing you need to do. The obvious drawback is that the Transterpreter takes up a good 23k of memory, leaving room for only small programs.

Once installed, the book guides you through parallel programming using Plumbing. One unusual thing (from my perspective as an artist/designer) is how the authors encourage the use of process diagrams to visualize what you’d like to do.

In this 11-line program, four LEDs blink at different rates, while a button toggles a fifth LED.

8 thoughts on “Parallel Programming: Plumbing on Arduino”

  1. Hi,

    I found that really really interesting..i’m not using Transterpreter for programming my arduino, do you think is even possible to create parallel processes ? Could I just add #include “plumbing.module ” or have I to use Transterpreter?

    thanks

  2. So let me get this straight…This is just a parallel syntax compiler? Since the Atmega chip is purely sequential in terms of instruction execution, the OS (‘firmware’) must be a sort of time-sharing implementation of parallel execution?

  3. That’s correct. It’s really an illusion of parallelism. I suppose that if you took a high speed video of the blinking lights, you’d see that they don’t quite change state at exactly the same time.

  4. Hi, Can you please let me know how to upload the Transterpreter to arduino?

  5. Thanks for the reply and sorry for not making the question clear. Actually I’ve gone through it, but unable to find how I can upload Transterpreter? . May be I missed somewhere. can you please let me know it in steps?
    P.S: I can open plumb and select the port once I plugged my Arduino (mega).

  6. I couldn’t find the occPlug in plugins menu. Then I tried to download the repository from a SVN location edited the build.xml with my folders. and it gaves an error when I compile it as “cannot find …..\….\Docinfo”

Leave a Reply

Your email address will not be published. Required fields are marked *