Category Archives: electronics

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.

Clock with Tics (presentation prototype)

Clock with Tics is an Arduino-powered 24-hour digital clock that displays expletives at random intervals.

A clock ‘ticks’. A ‘tic’ (note the different spelling) can be a mental disorder and can manifest itself in a number of ways; most seriously, someone suffering from “Tourette’s Syndrome” will blurt out swearwords involuntarily. I had thought of titling this piece “Time for Tourettes”, but the clock itself is tasteless enough.

This artifact is part of my series “The Technology of Good Intentions” which focuses on ‘failure’ in design. In this case, who has not had an electrical widget that has ‘gone on the fritz’ and suffers from momentary lapses?

The Arduino code for this project is available under a Creative Commons Attribution-Noncommerical-Share Alike 2.5 Canada License. Most of the electronic parts were obtained from futurelec.com and seeedstudio.com. The circuitry is split between two boards: the ATMEGA168 controller using the Arduino bootloader and clock chip/battery is separate from the four-digit display. Power is provided by a 9 volt 650 mA power supply. The 7805 voltage regulator runs quite hot and because of this it is mounted separately with an aluminum heat sink.

The clock is a DS1307 with a small battery backup to hold the correct time when the rest of the unit is without power. Each 5×7 LED display matrix is driven by a MAX7219 chip. The schematic for the entire clock is below.

The clock is mounted between three sheets of 3.5mm clear acrylic plastic. The two circuit boards are attached to opposite sides of the middle sheet, and the three sheets are held together using 25mm hex spacers. A hole is drilled in the middle plastic sheet to allow a small cable to connect the two main circuit boards. The construction SketchUp file is here.