Twitter Physical Client
In this project I’m building a physical Twitter client using Arduino and a flag, basically an arduino powered retweet indicator, whenever any of my tweets is retweeted some physical action will happen to notify me of that.
3. Laptop with a java IDE installed on it.
4. Yellow Led
5. 330 Ohm resistor
6. Servo motor (even a weak one would do, you don’t need a lot of torque)
7. Lego Blocks
8. Twitter ( Consumer Key / Consumer Secret) from the website.
This project requires basic arduino skills and some java development background.
Step 1: Register a Twitter Application
1. Log into dev.twitter.com
2. Sign in using your user name.
3. Click on create an app.
4. Fill in the values, You can put in anything in call back url or even leave it blank since its not a web app.
5. Copy the consumer key and secret values (you’ll need them later). you’ll find them in the OAuth section.
Step 2: Start by building your java application
The Java code goes in queries for retweets, sets a floor (to avoid listing historical retweets), and starting from that floor every time it queries it returns the number of retweets since the last query, this is done using an index that gets set with every query (rather than saving it to disk or DB).
I’m attaching the code, you’ll need to download it and modify the following classes.
1. Open the project on netbeans.
2. Make sure that the libraries “RXTXcomm.jar” and “twitter4j-core-2.2.2.jar” are imported, if they weren’t import them manually (you’ll find them in the lib folder).
3. Check which port your arduino is connected to, in my case it was COM10, and so i modified class “serial_test” constructor to reflect that.
a. open serial_test
b. go to static ports array PORT_NAMES and modify the windows entry to match yours (if you are using linux modify the linux value).
4. Open class “arduino” and change ConsumerKey and ConsumerSecret to match the ones you have from step 1.
5. Clean and compile, now the code is read.
Built using Twitter4j this requires that you should call the authenticate class first, slightly out of scope here but I’m willing to provide any needed help if required
here is the method that harvests the number of retweets.
public ArrayList get_retweets_from_last(String id)
Twitter twitter = new TwitterFactory().getInstance();
ArrayList ret_retweets=new ArrayList();
for (Status s: retweets)
System.out.println(“found “+ret_retweets.size()+” retweets”);
I then use the RXTXcomm api to transfer this value to the Arduino, the Arduino keeps track of how many retweets it received since it was reseted, this number is incremented every time it receives a new one from the Java application.
public void write(int s)
Finally I manage all of this from a control for loop with a timed delay (the reason here is that you only get a limited number of Twitter API calls per hour, if you exceed that you get blocked),
Step 3: Components Assembly
Using the prototyping board connect the following
For more detail: Twitter Physical Client
JLCPCB – Prototype 10 PCBs for $2 + 2 days Lead Time
China’s Largest PCB Prototype Enterprise, 300,000+ Customers & 10,000+ Online Orders Per Day
Inside a huge PCB factory: https://www.youtube.com/watch?v=_XCznQFV-Mw