Full tutorial: https://hofmannsven.com/2013/laboratory/arduino-twitter-library/
Last active
February 5, 2018 14:22
-
-
Save hofmannsven/6226895 to your computer and use it in GitHub Desktop.
Getting started with the Arduino Ethernet Twitter Library to send a Tweet to Twitter with a Button.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> // needed in Arduino 0019 or later | |
#include <Ethernet.h> | |
#include <Twitter.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void loop() { | |
if (digitalRead(buttonPin) == HIGH) { | |
// convert everything to string(char) | |
sprintf(buf, "This is tweet number %d via an #Arduino Ethernet Board!", i); | |
tweet(buf); | |
i++; | |
// zero delay | |
delay(0); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ethernet Settings | |
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // No need to change the default Mac address | |
byte ip[] = { 123, 456, 789, 0 }; // Insert your Ethernet IP | |
// OAuth Token | |
// Get your Token here: http://arduino-tweet.appspot.com/oauth/twitter/login | |
Twitter twitter("123456789-abcdefghijklmnopqrstuvwxyz"); | |
// Counter | |
int i=0; // start with zero | |
char buf[100]; | |
// Pin | |
int buttonPin = 9; // Pin for the push button |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void setup() { | |
pinMode(buttonPin, INPUT); | |
Ethernet.begin(mac, ip); | |
Serial.begin(9600); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void tweet(char msg[]) { | |
Serial.println("connecting ..."); | |
if (twitter.post(msg)) { | |
int status = twitter.wait(&Serial); | |
if (status == 200) { | |
Serial.println("OK."); | |
} else { | |
Serial.print("failed : code "); | |
Serial.println(status); | |
} | |
} else { | |
Serial.println("connection failed."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment