It Works………Kind of!


Okay, it’s been several weeks now.  I’ve tried many Twitter to Arduino and Twitter to Processing Sketches, but the best one is this one I found is this!

Twitter to Processing Sketch:


Twitter myTwitter;

void setup() {
myTwitter = new Twitter("yourTwitterUserName", "yourTwitterPassword");
try {

Query query = new Query(“sandwich”);
QueryResult result =;

ArrayList tweets = (ArrayList) result.getTweets();

for (int i = 0; i < tweets.size(); i++) {
Tweet t = (Tweet) tweets.get(i);
String user = t.getFromUser();
String msg = t.getText();
Date d = t.getCreatedAt();
println(“Tweet by ” + user + ” at ” + d + “: ” + msg);

catch (TwitterException te) {
println(“Couldn’t connect: ” + te);

void draw() {


This is a simple, elegant and very easy to setup Processing Sketch.  I’ve tested it with “Twitter1812” and it works perfectly.  Now, my assumption is that if this sketch can query or respond to specific word queries, we should be able to get it to seek two variables such as; CAN1812 or USA1812.  Before I can get there however, I want to make the output of this Processing sketch, into a function that will then turn on an LED through a Processing command.

I found a great Processing to Arduino Sketch, but unfortunately I lost the URL from the original site, so I apologize if I’m not recognizing the original creator.  Again, this is a very simple set of Sketches.  The first is the Arduino and the second is the Processing.  Basically Processing accesses Arduino through a dedicated serial port.  Bill’s introduction to Firmata last week was to hopefully bypass the Arduino code bit, but like many of my classmates, the libraries weren’t working on my operating system.

Here is the Processing Sketch:

import processing.serial.*; //This allows us to use serial objects

Serial port; // Create object from Serial class
int val; // Data received from the serial port

void setup()
size(200, 200);
println(Serial.list()); //This shows the various serial port options
String portName = Serial.list()[1]; //The serial port should match the one the Arduino is hooked to
port = new Serial(this, portName, 9600); //Establish the connection rate

void draw()
if (mouseOverRect() == true)
{ // If mouse is over square,
fill(150); // change color and
port.write(‘H’); // send an H to indicate mouse is over square
{ // If mouse is not over square,
fill(0); // change color and
port.write(‘L’); // send an L otherwise
rect(50, 50, 100, 100); // Draw a square

boolean mouseOverRect()
{ // Test if mouse is over square
return ((mouseX >= 50) && (mouseX <= 150) && (mouseY >= 50) && (mouseY <= 150));

And here is the Arduino Sketch:

const int ledPin = 13; // the pin that the LED is attached to – change this if you have a separate LED connected to another pin
int incomingByte;      // a variable to read incoming serial data into

void setup() {
// initialize serial communication:
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);

void loop() {
// see if there’s incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte =;
// if it’s a capital H (ASCII 72), turn on the LED:
if (incomingByte == ‘H’) {
digitalWrite(ledPin, HIGH);
// if it’s an L (ASCII 76) turn off the LED:
if (incomingByte == ‘L’) {
digitalWrite(ledPin, LOW);

Processing creates an interactive box, which when the mouse rolls over it, the Arduino LED turns on.  So, my basic assumption is this.  If Processing can receive an input from Twitter, it can write that input out as a function that can then turn an LED light off and on within Arduino.  If we can accomplish that task, switching the LED for a Motor Shield to power our flag gear and pulleys should be easy!

If anybody has any suggestions I’m all ears!


One Reply to “It Works………Kind of!”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.