Stripe: Arduino prototype

At Nut & Bolt I try to start prototyping as soon in the design process as possible. For me, it helps visualize what the end result is going to be. Also, having one or more prototypes works great as a development platform: allowing me to quickly try out different software and hardware variations and help me find and resolve issues as soon as possible.

Stripe Arduino prototype on the wall
The bare Stripe prototype on the wall in my studio.

In this post I will describe the components of the first Arduino and Python-based prototype for Stripe. Be sure to read that link if you haven’t already. I’ll give an explanation on what the prototype is supposed to do, the hardware components and the software used.

What does it have to do?

The prototype has to be able to do the following:

  • Display the current time of the day as a bargraph of white LEDs on a strip
  • Display today’s Google Calendar events as colored blocks on the strip
  • Periodically update the display to reflect changes in events
  • Make it very easy for me to try out different scripts

Hardware

The prototype setup consists of a computer running python, an Arduino microcontroller board and an LPD8806 RGB led strip. They are hooked up to each other like this:

Laptop - arduino - led strip
The laptop talks to the Arduino via serial over USB. The Arduino talks to the LED strip via a clock and data line in an SPI-like protocol.

The connection between the laptop and Arduino is USB. The LED strip’s clock and data pin are connected to two digital pins on the Arduino.

Arduino

The Arduino is always my go-to platform when I need to prototype something with a microcontroller. It’s easy to hook up (one USB cable), there are many software libraries available and the internet is riddled with example code. In this case, the Arduino acts as a translator between the computer’s serial commands and the LED strip’s SPI-like control signals.

LPD8806 RGB LED strip

To be able to show a bargraph and colored blocks, I needed a LED strip with individually addressable RGB LEDs. These LEDs combine a red, green and blue LED in one package. There are many types of addressable RGB LED strips. I finally chose for a strip based on the LPD8806 controller, like this one at Adafruit. This controller is quite advanced, requiring only a clock and data line for driving a whole strip of LEDs with 21bit color (7bit per color, 2 million colors total).

Software

Python and google-api-python-client

I use Google Calendar to manage my calendar and events. It would be nice to be able to tap into this information.
Google Calendar
Google provides APIs to many of their services including their Google Calendar service. They have example code in many different languages but for this case I chose Python. It does not have to be compiled and runs on all platforms, even embedded Linux. The final product will run on embedded Linux, so some of the code for the prototype can be reused.

I will explain more about the Python side of things in a later post. In short, it works like this: you need google-api-python-client to communicate with Google’s servers. You generate an API key in the Google API Console and plug that into your Python code. The script retrieves today’s events from Google Calendar and translates that into an array of pixel values for the LED strip.

In the prototype, pySerial is used to send commands to the Arduino via the usb serial port.

Arduino software

The LPD8806 library for Arduino by cjbaar is used to interface with the LED strip. A small Arduino sketch handles the incoming serial signals and drives the LED strip accordingly.

The Arduino setup routine is simple. It initializes the LED strip, opens up serial communication and sets all LEDs on the strip to off.

void setup() {
  // Start up the LED strip
  strip.begin();

  // Serial communication at max speed
  Serial.begin(115200);

  // Update the strip, to start they are all 'off'
  strip.show();
}

The loop also speaks for itself. The serial buffer is read three bytes at a time: one red, one green and one blue byte. If the buffer contains ‘{‘, the pixel counter is reset to zero. If the buffer contains ‘}’ the data in the pixel buffer is pushed to the LED strip.

void loop() {
  // Wait for the buffer to have 3 bytes of data
  while(Serial.available() > 2) {

     // Read the three bytes into red, green and blue components
     r = Serial.read();
     g = Serial.read();
     b = Serial.read();

    if(r == 123) {   // 123 = '{' - start of sequence
      i = 0;         // reset the pixel array counter
      continue;      // exit the while loop
     }
     if(r == 125) {  // 125 = '}' - end of sequence
       strip.show(); // write out the pixel array
       continue;     // exit the while loop
     }

     // Update the pixel array with the values for red, green and blue
     strip.setPixelColor(i++, r, g, b);
  }
}

The full Arduino sketch can be downloaded here: stripe_serial.ino (2kB)
You’ll also need the LPD8806 library by cjbaar.

And now?

For now, the prototype is a good base to try out different mappings, resolutions, colors and behaviors. The following screen might seem familiar:

Google Calendar

Imagine rotating this view sideways, so that the green blocks are represented by green LEDs. The current time (indicated by a red line in the screen shot above) is indicated by white LEDs:

Stripe Arduino prototype on the wall

On this blog, I am documenting the design of an internet-enabled linear LED clock: Stripe. Want to know more? Have a look at all posts about Stripe, subscribe to the RSS feed or follow me on Twitter

Leave a Reply