Using Twitter with Arduino

0 votes
91 views
asked Dec 15, 2015 in Computer by wikiandroid (10,110 points)
How to tweet with Arduino?

1 Answer

0 votes
answered Dec 15, 2015 by wikiandroid (10,110 points)

Hey there! Today I dusted off my Arduino to write a tutorial I think you will like enough. This is post messages on Twitter from Arduino. It is easy and fast. Only we need:

  • Arduino.
  • Ethernet Shield.
  • Ethernet Cable.
  • Twitter account.

If we have the Ethernet Shield, we can use an Arduino Yun.

The process is simple . We will continue to give us the steps in this page .

STEP 1: GET THE TOKEN

The first thing to do is get a  token to publish our account from Arduino. To do this, we enter  this link.

After authorizing the application, we obtain the  token we wanted:

Arduino token twitter

STEP 2: DOWNLOAD THE LIBRARY

The bookstore can download from this link . To install, unzip the content:

  •  Windows : My Documents \ Arduino \ libraries \
  • Mac : ~ / Documents / Arduino / libraries
  • Linux : ~ / sketchbook / libraries

After unpacking the library, we restart the Arduino IDE for changes to take effect.

STEP 3: WRITE THE CODE

The code is explained with comments in it. Still, he does not miss it. Too easy.

All you have to do is enter your  token on the line  Twitter twitter "TOKEN ENTER HERE" ;  and configure an IP in byte ip 192 168 250 ; . After this, just charge the Arduino the following code: 

LOOK AT THE COMMENT

When the code is executed and, if all goes well, we will see in our Twitter account a new message.

commented Dec 15, 2015 by wikiandroid (10,110 points)
Code :
#include  
#include
#include
 
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
 
byte ip[] = { 192, 168, 0, 250 };
 
Twitter twitter("INTRODUCIR TOKEN AQUI");
 
char msg[] = "Hi!!!";
 
void setup()
{
  delay(1000);
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
  
  Serial.println("Estableciendo conexion con Twitter ...");
  if (twitter.post(msg)) {
    int status = twitter.wait(&Serial);
    if (status == 200) {
      Serial.println("OK.");
    } else {
      Serial.print("Error : code ");
      Serial.println(status);
    }
  } else {
    Serial.println("Connection failed.");
  }
}
 
void loop()
{
}
...