Introduction: Tweet With Your Intel Edison

About: I'm an Electrical Engineer who dabbles in just about everything. By trade, I'm a controls engineer and design machines for the largest manufacturing plants in the world. At home, I make a lot of embedded syste…

So, you've got this cool new Edison, but what to do with it? Well, it DOES talk to the internet fairly well, so let's make it talk to the internet!

Interestingly enough, the ethernet libraries for Arduino work just as well on the Edison, so why not use them?

I am piggybacking off of a very good tutorial found here: http://arduino-tweet.appspot.com/
As a result of my piggybacking, I am using (and trusting) NeoCat's app that gets the twitter token you will need to tweet with your Edison. While I am a rather trusting person (perhaps destructively so), you may want to dig around to get your token from https://dev.twitter.com/ . Unfortunately, at the time of writing this, the developer site is by invite only....so NeoCat's option was definitely the best.

So, to get started, visit NeoCat's website, follow his/her tutorial to get the twitter library and your twitter token: http://arduino-tweet.appspot.com/

As NeoCat mentioned on their site, please don't abuse the service. Keep your tweets sparse. If you need something that tweets every 6 seconds, you should set up your own server and twitter app.

I am also counting on the fact (it IS a fact, right?) that you have already gone through the Getting Started tutorials Intel has so kindly made for us. You can find them here: https://communities.intel.com/docs/DOC-23147


And, of course, FOLLOW ME ON TWITTER! @foxrobotics

Step 1: Let's Add Some Sensors

A randomly tweeting Edison can be fun, but let's add some sensors to it.

For this instructable, I will be using the Grove Starter Kit for Edison to save myself a bit of time. I'm normally a proponent of breadboards and custom circuit boards, but hey, why not? You can easily replicate this by connecting a button yourself that has a 10k pull down resistor. Search for "Arduino button circuit" online to find it.

In this example, I will be connecting the button to D8. I will also be connecting a light sensor to A0 (again, search "Arduino light sensor" for explicit circuits). Connect them as shown in the picture if you have the same Grove kit.

Step 2: Let's Write Some Code!

Your code in all its glory! You'll notice that many bits and pieces are "missing" from NeoCat's code. The Linux kernel handles a lot of that for you. I did remove the wait command (if you saw his/her code) as it always hangs. I don't know if this is due to a change in the Twitter API, his/her site, or something in the Edison.

(Note, if the Instructables website messes up the formatting, copy and paste everything, paste it in the Arduino Edison IDE, do a search and replace for "
" and replace with nothing. Then go to Tools>>Auto Format. Your code will look happy again.)

#include <SPI.h>
#include <Ethernet.h>

#include <Twitter.h><br><br>void setup(){
    pinMode(8, INPUT);
}

void loop(){

    if(digitalRead(8)){
        tweetMessage();
        delay(1000);
    }
}

void tweetMessage(){
    Twitter twitter("your token here");
    //Our message (in lolcat, of course)
    String stringMsg = "All ur lightz be ";<br>    stringMsg += analogRead(0);<br>    stringMsg += " out of 1023. Dey belongs to us nao.";

    //Convert our message to a character array
    char msg[140];<br>    stringMsg.toCharArray(msg, 140);<br>
    //Tweet that sucker!
    twitter.post(msg);
}

Step 3: Make Some Changes of Your Own and Tweet Like Mad!

Click "Upload" (the right pointing arrow button) and you are done! Viola!

My code is meant to be insanely simple so it is easy to follow. But, add your own sensors, actuators, random furry animals, and make it your own!