Step 5: Arduino + Twitter + Ethernet Fun

A neat character named Neocat made the Arduino Twitter Library. Instead of storing your user ID and password in Arduino code, it issues a token to use the Twitter API. This token can be revoked at any time which is good if you accidentally post your whole code WITH the token to somewhere. Yes. I did that. Oops.

The difficulty I found is that it only accepts char[] arrays as tweets, so a character array must be declared then populated. Since my code generates Strings, I had to convert the String to a character array before passing it off to my Twitter function.

Here's what I added to the example code to make it a function. The Serial.print lines are there just to help with debugging. I also initialized the variable at the top of the sketch with char msg[125]; // make a nice fat buffer (125 characters) for tweets

If your tweet size exceeds that array size, YOU WILL HAVE PROBLEMS! I spent three hours trying to figure out why my analogRead functions were adding themselves to each other instead of generating new readings.

void postTweet(String tweet){
   	   String termTweet = tweet + "\0" ;// Terminate the tweet with a null
	   Serial.println(" - Terminated tweet");
	   int twtlen = (termTweet.length()+3); // count the characters, add 3 just in case
	   Serial.println(" - Tweet length");
	   termTweet.toCharArray(msg,twtlen); // Convert it to an array called msg
	   Serial.print("Attempted tweet ");
	   Serial.println("connecting ...");
	   if (twitter.post(msg)) {

The rest of the posting code is in the Twitter library.
<p>I just want to say thank you for making this instructable. I've been having a lot of trouble getting my INA126P amplifier to work. I've searched the web extensively to find some information that would help me get my amplifier to work. I gave it one last attempt this morning and stumbled upon your instructable. I noticed that you did not connect pin 5 to GND (which is what the data sheet says to do). I disconnected pin 5 from GND and now my amplifier is working! Thanks again!</p>
This is creative,cute and genius all in one! &lt;3 it so much. I want this for my kitty!
love it!
Cute project!
Thank you :D

About This Instructable




More by thoughtfix:Mint-Sized Success Meter (quit smoking!) with Arduino Arduino powered Haunted Pumpkin Make your pet dishes tweet! 
Add instructable to: