Skip to content

Instantly share code, notes, and snippets.

@hofmannsven
Last active February 5, 2018 14:22
Show Gist options
  • Save hofmannsven/6226895 to your computer and use it in GitHub Desktop.
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.
#include <SPI.h> // needed in Arduino 0019 or later
#include <Ethernet.h>
#include <Twitter.h>
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);
}
}
// 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
void setup() {
pinMode(buttonPin, INPUT);
Ethernet.begin(mac, ip);
Serial.begin(9600);
}
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