After I successfully managed to control a LED strip via Twitter with an Arduino Uno and a Wifi Shield, I wanted to add a webcam, so the Arduino could reply with a picture of the newly colored lights. For this purpose, I bought an Arduino Yún. Like other Arduino devices it has an ATmega processor. But the the thing that is special about the Yún is that it also has an Atheros AR9331 processor, which supports Linux! And among other features, the board has wifi, a USB-A port, a micro-SD card slot, digital input/output pins and a micro USB connection, all of which I need for this project.
What it does
Every 30 seconds, Twitter is searched for the latest public tweet which contains the hashtag "#twitmaslights:", followed by a color. This color can be given in hexadecimal notation, or as one of the 140 official html color names. When a new tweet is encountered, the text after "#twitmaslights:" is parsed and checked for a valid color code or name. When this succeeds, the colors of the LED strip change and the webcam takes a picture. This picture is added to a reply from @twitmaslights to whoever posted the #twitmaslights tweet, so at least I'm not the only one who gets some satisfaction from the Christmas lights in my living room 🙂
How it works - or rather: how it doesn't
It took me some time to understand the way the two "sides" - the ATmega (Arduino) and the Atheros (Linux) - had to be used to communicate. The Bridge library offers various methods to do this, but what, where, how, when and why wasn't very clear to me in the beginning.
At first, I used the ATmega to do all the heavy work, including searching for tweets, parsing, checking for valid color codes and tweeting updates. Because there are many string (text) operations involved with this, the little RAM memory (only 2.5 KB!) of the Arduino microcontroller soon turned out not to be enough. And that was at the point I didn't even connect the camera yet!
I also used Temboo, which offers a very inventive and easy way to connect a Yún to many different online services (Twitter, Facebook, Google+, Paypal, Instagram, FourSquare... you name it!) I was very impressed with this, until I found out that a user has only a limited amount (1000 a month) of api requests. If you want more, you'll have to pay for an extended plan. Another drawback of Temboo is its memory usage. In my case it ate up at least another 10% of program memory and showed unpredictive behaviour when I ran out of RAM on the Arduino side. On the other hand, a big pro for Temboo is their support: they actively took the initiative to contact me when they noticed I was having trouble sending tweets from the Yún.
How to really get it to work
I figured out (why hadn't I done that before?!) that I had to use Linux side of the Yún to do all the heavy work. You can write your own Python scripts, save them on a micro SD card and call them from the Arduino side. It's also easy to send data from one side to another. If you know how this works, know how to install additional Python modules the right way, use that method to install Twython and use this guide to succesfully connect a webcam, tweeting an image even becomes easier and more powerful than using Temboo!
Tijd voor een ander kleurtje. Maar ik kan weer niet kiezen. Dus: #twitmaslights:random
— Ralph Crützen (@RalphCrutzen) 22 december 2013
.@RalphCrutzen changed the @twitmaslights to random color b4f017. pic.twitter.com/E0sE7HfSeV
— Ralph's X-mas Lights (@twitmaslights) 22 december 2013
2 gedachten over “Twitmaslights: use an Arduino Yún to control colored led lights with Twitter”