Introduction: Tweet With Your Intel Edison

Picture of Tweet With Your Intel Edison

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

Picture of 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!

Picture of 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!

Picture of 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!

Comments

ainsey11 (author)2014-12-15

Hi There,

Love the instructable! I just got my board through today and have been tinkering around with it, I have uploaded your code and used my twitter auth token, however when I press the button it doesn't tweet anything? Is there a way to view logs etc?

Thanks,

Ainsey11

A_Steingrube (author)ainsey112014-12-15

A few ideas:

1) Are you using the token you got from NeoCat's website or are you using one that you have gotten previously? I haven't looked too deeply into it, but I would be willing to be that your actual twitter token and the one being used for NeoCat's tweeting service are different. Since the library goes to NeoCat's twitter app, you would need his/her token for your account. You also have to give NeoCat's app the permission to post for you.

2) Have you set up your wifi? Is it still connected? You can test this by opening your Edison in an SSH terminal (like putty), logging in, and then typing "ping www.instructables.com". If you are connected to the internet, you should get a response back.

3) You are sending a lot of identical tweets back to back and Twitter is blocking them. Make sure you have a delay like I show in the code (or add more sophisticated debounce), that your button is wired correctly (you should have a 10k pull-down resistor to ground), that your button is on the correct pin, and that your button is working. To test if your button is working, open the Arduino IDE for Edison and type the following. If your button works, you should get a bunch "It works!" on your serial monitor.
void setup(){ pinMode(8, INPUT); Serial.begin(9600);}
void loop(){if(digitalRead(8) Serial.println("It works!");}

4) You can try NeoCat's code to debug the connection. Replace "twitter.post(msg)" with this:

if (twitter.post(msg)) {
    int status = twitter.wait();
    if (status == 200) {
      Serial.println("OK.");
    } else {
      Serial.print("failed : code ");
      Serial.println(status);
    }
  } else {
    Serial.println("connection failed.");
  }

ainsey11 (author)A_Steingrube2014-12-15

Thanks for getting back to me!

Turns out I had my button connected to the wrong connector!

DUUhhhh :D

Cheers!,

Ainsey11

A_Steingrube (author)ainsey112014-12-15

Heheh, glad you figured it out ^-^

Awesome instructable! And that identical tweets thing caught me off guard, almost made me go mad that it wasn't working even though the code was perfect!

Jonathanrjpereira (author)2015-09-20

does the #include<Ethernet.h> support the Intel edison being connected to wifi instead of ethernet over usb.

In short does your code work for edison boards connected to wifi?

BertugBerkay (author)2015-04-11

Thanks. I made it.
Now time to read from twitter timeline.

hybvfr (author)2015-03-22

I made it. Thanks!

Geeve George (author)2015-01-05

Hi A_Steingrube,

I wanted to display a tweet in my 16*2 Grove RGB LCD Display!

Can you help me with the code!

Thanks alot !

Regards,

Geeve

About This Instructable

21,079views

8favorites

License:

Bio: 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 ... More »
More by A_Steingrube:Quick and Dirty Mosquito TrapSend Texts with Intel Edison (Party Alarm)Email with Intel Edison (Intruder Alarm)
Add instructable to: