Twitter controlled Christmas tree

From DP

Jump to: navigation , search



@tweet_tree was the Dangerous Prototypes 2009 Christmas tree that anyone could control from Twitter. All they had to do was tweet a color to @tweet_tree. A small embedded web server read the tweets, and faded the fiber optic tree to the colors sent. New tweets were grabbed every few seconds.


Tweet overview.png

A business card sized web platform connected to Twitter once every 20 seconds and grabbed new tweets. A multicolor LED in our fiber optic Christmas tree fades to the new color.

If there’s are more than one color in a tweet, or multiple tweets, the tree fades between them until it reaches the most recently sent tweet.

We used Twitter as a control mechanism because it’s easier for the tiny internet device to act as a client than a server. If you contacted the @tweet_tree directly, not only would it crash with more than a few users, but we’d have to configure routers and use a service like DynamicDNS to tunnel into our local network. Instead, we let Twitter and their servers handle the user input, the @tweet_tree just contacts Twitter and pulls datafeeds as needed. This arrangement is a lot more solid than opening a tiny embedded server to the world.

Using it

To choose the color of our tree, just send a color to @tweet_tree on Twitter.

@tweet_tree red, green, purple, green, p, g, r, b

@tweet_tree understands red, orange, yellow, green, blue, and purple. Send one color, or combination of colors to morph through. Separate multiple colors with a comma. Only the first letter of the color matters, r,o,y,g,b, & p, are acceptable color commands.

@tweet_tree red, *ff0000, green, *00ff00, blue, *0000ff

You can also blend custom colors using 24 bit hexadecimal color codes. Here’s a color picking tool to help you choose values. Send the value as *rrggbb, where rr=red, gg=green, and bb=blue. We used the * designator because the more common # is already used for Twitter hash tags.


The tweet_tree has three primary components.

Web platform

Tweet guts.jpg

Our open source web platform does the heavy lifting. It has all the hardware we need to connect to Twitter, parse tweets, and convert them to colors. The color(s) are stored in memory and sent to the ShiftBrite LED over a simple 3-wire interface.

Shiftbrite high power LED

Tweet shiftbrite.jpg

A ShiftBrite high-power LED blasts the colors sent in the tweets.


It only takes three pins to control the ShiftBrite, we used IO2-4 on the web platform IO header. The EI pin on the shiftbrite module should be permanently enabled by connecting it to ground. The module requires a 5+ volt power supply; we tapped the same supply we used for the web platform.

Fiber optic tree

Tweet tree.jpg

A small fiber optic Christmas tree, but you could use more ShiftBrites to light a full-size tree or yard display.

We removed the original guts from the base of the fiber optic tree and replaced them with the ShiftBrite. A major concern was that the LED wouldn’t be bright enough to replace the original mini-halogen lamp, but the ShiftBrite works perfectly.


The latest firmware download is on the project Google Code page here. The code is written in C, and compiled with the free evaluation version of the Microchip MPLAB® C Compiler for PIC24 MCUs and dsPIC DSCs (formerly known as the MPLAB C30 Compiler).

Tweet tree firmware.png

The firmware uses an adapted version of the #twatch source code to connect to Twitter over the internet. It opens a TCP connection and sends a search query for ‘@tweet_tree’, the response is a JSON formatted data file like this.

Tweet tree json results.png

A JSON parsing state machine searches through the data for the ‘text’ and the ‘id’ tags. The text tag value is processed for color commands. The value of the first id tag is stored too. We’ll use it to limit results to new tweets in the next search query. Hint: try JSONView to work with JSON in Firefox.

If a new color command is found, the LED fades into the new color. If multiple commands or tweets are found, the colors morph from oldest to newest, with a 5 second pause between each. The tree always ends on the most recently tweeted color.

Every minute, or after completing a stored sequence, whichever takes longest, the web platform queries Twitter for fresh tweets. It appends the saved id tag value to the search query so the feed only returns new tweets. Twitter limits the number of queries you can make in an hour, but 60 is well below the limit.

The ShiftBrite is controlled with bitbang routines from our RGB remote control pumpkin project.

Compiling the firmware

This firmware uses the free Microchip TCP/IP stack. If you want to compile the firmware yourself, download the TCP/IP stack and follow the instructions in main.c.

Taking it further

Twitter-controlled holiday possibilities are endless. The web platform can Twitter-enable a Halloween or Christmas yard display. Multiple Shiftbrite modules could be tied together to light a large Christmas tree, or substitute a TLC5940 16 channel LED driver to control individual LEDs.