Twitter Mention Mood Light — a mood light that alerts you when @username is mentioned on Twitter.
This is a simple intro in how to control your Arduino from Twitter. If you are new to Arduino Twitter / Arduino Processing Twitter / Arduino Python Twitter / Twitter Mood Light, then please refer to simpleTweet_00_processing and simpleTweet_01_python (and How to install Python packages on Windows 7 ) for a crash course.
The Arduino Twitter mood light has been around for a few years. I made one in early 2010 and recently decided to update it for Twitter OAuth protocol (step 5.) This instructable has both the [ Arduino Processing Twitter ] and [ Arduino Python Twitter ] versions.
The general idea: You’ve got a LED generating a peaceful glow, cycling through a bunch of colors, and meanwhile you’ve got Processing or Python listening to Twitter for any mention of @yourUsername. When it finds a Twitter status with @yourUsername it writes to Arduino over Serial and Arduino changes the LED from peaceful glow to alert.
The circuit board (step 6) has two buttons: Reset and Send. The reset button changes the LED from “alert” back to “peaceful glow.” The send button sends a Twitter status update to your Processing or Python layer, and from there on up to Twitter. When pressing the SEND button, hold it down until you see the flash of WHITE LIGHT (approx 1 second.) This confirms the button push has been read by Arduino.
There is some confusion about Twitter Rate Limits . The Rate Limit is the number of times Twitter will let you hit it’s servers per hour, currently 350 hits per hour. Go over that number and Twitter will block you. I made the same provision for this in both Processing and Python: wait 15 seconds between hits. In Processing, in void draw() , see delay(15000); . In the Python, in the while clause, see time.sleep(15). This does not affect the timing of any button pushing or Serial calls.
The Arduino code is the same for both Processing and Python except when Arduino listens to Serial. Both Processing and Python pass an integer value of 1 (arduino.write(1) ) but Arduino receives a different value (numeric / ascii) from each, which is why you’ll see these two lines in the Arduino code:
if (serialMsg == 1) state = “mention”; // processing
if (serialMsg == 49) state = “mention”; // python
This is because I’m not sure how to pass a string value of “mention ” over Serial in Python. It’s not critical, so I’ll leave working as above, but if anyone has a solution for sending a string (arduino.write(“mention”) ), particularly in Python, please post in the comments below.
The center of this project is the getMentions() function. It’s interesting to compare how they look in Processing and in Python.
In both cases the id value received is in “long” format. By converting from “long” to “string” with str() we’re able to compare the value and act on it. I had trouble doing that in long format.
Step 2: Arduino
twitterMentionMoodLight_arduino
for use as is with either:
twitterMentionMoodLight_processing
twitterMentionMoodLight_python
Generate a peaceful glow until someone on twitter mentions you.
Requires a circuit with: two buttons and a pwm rgb led light, and
3 resistors at 220 ohm; 2 resistors at 100 ohm; 2 resistors at 10k ohm.
Shout out to Tom Igoe, Adafruit, lurkers and msg boards everywhere.
learn more at: http://www.instructables.com/member/pdxnat/
Install twitter4j (Processing)
You’ll need to install the twitter4j library so it can be used by Processing.
Get it here: http://twitter4j.org/en/index.html#download
Install it here (or equivalent): C:\Program Files\processing-1.5.1\modes\java\libraries
You’re done.
Access it here: Processing > Sketch > Import Library… > twitter4j
And when you do, it’ll add this to the top of your code:
import twitter4j.conf.*;
import twitter4j.internal.async.*;
import twitter4j.internal.org.json.*;
import twitter4j.internal.logging.*;
import twitter4j.http.*;
import twitter4j.api.*;
import twitter4j.util.*;
import twitter4j.internal.http.*;
import twitter4j.*;
Incidentally, you’ll also add Serial I/O from the Sketch > Library, but that’s not important right now.
So why do you need twitter4j? The short answer is that it provides you with simple functionality so you don’t have to write a whole bunch of crazy code every time you want to access Twitter. We use twitter4j because it’s awesome and it makes our job easier.
Step 6: Circuit Board
This is a great board for all-purpose prototyping. Two buttons and a PWM RGB LED. For this configuration, the LED must be PWM to work
This Twitter Mention Mood Light is not particularly unique. You’ll find other examples across the internets. But what makes this special is that it’s up to date with Twitter OAuth and you’ve got code comparisons in Processing and Python.
If you are new to Arduino Twitter / Arduino Processing Twitter / Arduino Python Twitter / Twitter Mood Light, then please refer to simpleTweet_00_processing and simpleTweet_01_python (and How to install Python packages on Windows 7 ) for a crash course.
TwitterExceptio
twitterMentionMoodLight
simplejson
For more detail: Twitter Mention Mood Light using Arduino