Well, I needed a TwitterCliënt getting a twitter feed, but using less SRAM than the one from the example. Also I find the example one being very slow en not responsive.
This is what I made off it. Of course you'll need an Arduino Ethernet or an Arduino with EthernetShield
/*
* TWITTERFEED SHOWN on SERIAL MONITOR
*
* last changed 23/02/2012
*
* Version 1.0
*
* Arduino 1.0 is needed !!!
*
* Made by JO3RI check check http://www.jo3ri.be/arduino
*
*/
#include <SPI.h>
#include <Ethernet.h>
#include <TextFinder.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xE4 };
byte ip[] = { 192,168,1,10}; //change this
byte subnet[] = {255,255,255,0}; //change this
byte gateway[] = {192,168,1,1}; //change this
byte dns[] = {192,168,1,1}; //change this
EthernetClient client;
String TwitterName ="JO3RI"; //change this to your own twittername, or follow me ;-)
char tweet[140];
String SearchString ="<title>";
byte charsize;
char serverName[] = "api.twitter.com"; // twitter URL
void setup() {
// initialize serial:
Serial.begin(9600);
// attempt a DHCP connection:
Ethernet.begin(mac, ip, dns, gateway, subnet);
// connect to Twitter:
delay(3000);
}
void loop(){
Serial.println("connecting to server...");
if (client.connect(serverName, 80)) {
TextFinder finder( client,2 );
Serial.println("making HTTP request...");
// make HTTP GET request to twitter:
client.print("GET /1/statuses/user_timeline.rss?screen_name=");
client.print(TwitterName);
client.println("&count=1 HTTP/1.1");
client.println("HOST: api.twitter.com");
client.println();
Serial.println("sended HTTP request...");
while (client.connected()) {
if (client.available()) {
Serial.println("looking for tweet...");
SearchString = SearchString + TwitterName + ": ";
charsize = SearchString.length() + 1;
char StartHere[charsize];
char EndHere[] = "</title>";
SearchString.toCharArray(StartHere,charsize);
if((finder.find("<item>")&&(finder.getString(StartHere,EndHere,tweet,140)!=0)))
Serial.println(tweet);
break;
}
}
delay(1);
client.stop();
}
Serial.println("delay...");
delay (60000);
// don't make this less than 30000 (30 secs), because you can't connect to the twitter servers faster (you'll be banned)
// off course it would be better to use the "Blink without delay", but I leave that to you.
}
Meanwhile, I found out how the get a hashtag feed, so you can show the last tweets holding a hashtag like #Arduino.
hurray hurray.
/*
* TWITTERFEED SHOWN on SERIAL MONITOR
*
* last changed 27/02/2012
*
* Version 2.0 hashtag version
*
* Arduino 1.0 is needed !!!
*
* Made by JO3RI check check http://www.jo3ri.be/arduino
*
*/
#include <SPI.h>
#include <Ethernet.h>
#include <TextFinder.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xE4 };
byte ip[] = { 192,168,1,10}; //change this
byte subnet[] = {255,255,255,0}; //change this
byte gateway[] = {192,168,1,1}; //change this
byte dns[] = {192,168,1,1}; //change this
EthernetClient client;
char TwitterHashtag[] = "arduino"; //change this to your own twitter hashtag, or follow arduino ;-)
char tweet[140];
char serverName[] = "search.twitter.com"; // twitter URL
void setup() {
// initialize serial:
Serial.begin(9600);
Ethernet.begin(mac, ip, dns, gateway, subnet);
// connect to Twitter:
delay(3000);
}
void loop(){
Serial.println("connecting to server...");
if (client.connect(serverName, 80)) {
TextFinder finder( client,2 );
Serial.println("making HTTP request...");
// make HTTP GET request to twitter:
client.print("GET /search.atom?q=%23");
client.print(TwitterHashtag);
client.println("&count=1 HTTP/1.1");
client.println("HOST: search.twitter.com");
client.println();
Serial.println("sended HTTP request...");
while (client.connected()) {
if (client.available()) {
Serial.println("looking for tweet...");
if((finder.find("<published>")&&(finder.getString("<title>","</title>",tweet,140)!=0)))
Serial.println(tweet);
break;
}
}
delay(1);
client.stop();
}
Serial.println("delay...");
delay (60000);
// don't make this less than 30000 (30 secs), because you can't connect to the twitter servers faster (you'll be banned)
// off course it would be better to use the "Blink without delay", but I leave that to you.
}
I'm pretty new to this whole Arduino and Twitter thing so I was wanting to ask a few questions if I could
Does the code that you have written and posted allow me to use my Arduino and ethernet shield to scan twitter (or my twitter profile for a specific hashtag) to then control something attached to the arduino?
Thanks
Clive
Hi Clive. With mu code you'll be able to follow a twitterperson and show it's tweets. You can use it to find a word or hashtag in the tweet, but you'll have to change the code a little bit.
If you want the Arduino to do things, depending on the words after the hashtags, you'll have to add even more code.
If you're new to Arduino, this will not be easy, but don't give up, we all had to start somewhere.
I'm trying to make an Arduino app that will trigger actions based on a hashtag coming up in the public stream....Using the REST API (search) every 30 seconds would work...But wouldn't that give me duplicate tweets with the target hashtag from previous searches? Wouldn't Twitter's Streaming API be better suited for this app?
Do you have any plans to use Twitter's Streaming API for your Twitter client?
I haven't planned to do that, but I shouldn't be that hard. Most important part is the textfinder part. All you have to do, is use an other rss or html feed.
Feel free to implement your own and show us your results.
if (client.connect()); shouldn't this be: if (client.connect(serverName, 80)) {
while (client.connect()) shouldn't this be: while (client.connected()) {
and ... you have to be sure, your wifi shield get's an ip for a dns-server. I'm guessing you're using dhcp to get ip, mask, gw and dns. Maybe you should try static first.
good luck and if it works, don't forget to post something to show off.
Oh, and if does work, would you be so kind to just put my name in your code? Thanks
frankly speaking, i'm really new to this arduino thing.. i would like to ask for your favor..
currently i have 2 unit of sure electronic 32x16 led matrix that i have connected to my arduino UNO..
and i have also bought an ethernet shield..
as i am writing this post, i have succeed in displaying character on the LED matrix display..
now i want to connect the ethernet shield to my UNO so that i can receive witter update and display it on the LED matrix display..
so my question is, do i need to merge your TwitterClient code into my existing LED matrix display coding or do i just upload your code to my UNO and it will automatically display the update accordingly on the LED matrix? if i do need to merge your TwitterClient code, how am i going to do so? as for now thats my only question.. hope you can help me solve this.. thanks jo3ri..
It's nice you want to use my code, Thanks. So, because you're new to Arduino, you probably will have to read a lot about coding and stuff.
For your question, I'll give you some guidance. Want you'll need to do is combine the code for the Twitter client with the code for showing it on a DOT matrix. It is possible (I did this in an other project of mine: CastDuino, google it, if you want, but CastDuino is way more complicated).
My Twitter client get's the tweet and puts it in a buffer for show it on the serial monitor. You can use the same buffer to show the tweet on an LCD or DOT-Matrix. It isn't that hard to accomplish.
This is only a part of the code, but you should put instead of the part: Serial.println(tweet);
// show tweet buffer
wd = HT1632.getTextWidth(tweet, FONT_7X5_WIDTH, FONT_7X5_HEIGHT);
HT1632.drawTarget(BUFFER_BOARD(1));
HT1632.clear();
HT1632.drawText(tweet, 2*OUT_SIZE - i, 0, FONT_7X5, FONT_7X5_WIDTH, FONT_7X5_HEIGHT, FONT_7X5_STEP_GLYPH);
HT1632.render();
HT1632.drawTarget(BUFFER_BOARD(2));
HT1632.clear();
HT1632.drawText(tweet, OUT_SIZE - i, 0, FONT_7X5, FONT_7X5_WIDTH, FONT_7X5_HEIGHT, FONT_7X5_STEP_GLYPH);
HT1632.render();
i = (i+1)%(wd + OUT_SIZE * 2);
I've started a similar project that uses a freetronics etherTen board(basically a board similar and compatible with the arduino).
I hooked it up to a 20 by 4 LCD display and everything is going fine. I'm just stuck on coding with the board that is suppose to connect it to the internet to retrieve tweets from my twitter account. do i just run your code and edit what is necessary to get it up and running then edit it?
also how do i get the ip, mac address, subnet mask, gateway and dns? do i just leave it as it is and rely on dhcp or?
appreciate your help. Have a few books on arduino but need a little kick to get this up and running.
First just try the code as is, but manually change ip, mask, gw and dns (the code doesn't use DHCP). You should know this things from your own network.
byte ip[] = { 192,168,1,10}; //change this
byte subnet[] = {255,255,255,0}; //change this
byte gateway[] = {192,168,1,1}; //change this
byte dns[] = {192,168,1,1}; //change this
ip: pick a free ip in your network
subnet: take the same one from your computer
gateway: take the same one from your computer
dns: take the same one from your computer
juest leave the mac address as is.
once this is running, you can continue to get the message on your LCD