Intel Galileo Button to Tweet Test
I was finally able to my Galileo to tweet and it was due to the help of the Tweet Library for Arduino.
http://arduino-tweet.appspot.com/
I'm currently thinking of different ways to use this in a project.
As for the guts of the project:
Breadboard:
I wired my button up similar to how they do it on the arduino's official website: http://arduino.cc/en/tutorial/button
Arduino Code:
#include <SPI.h> // needed in Arduino 0019 or later
#include <Ethernet.h>
#include <Twitter.h>
// The includion of EthernetDNS is not needed in Arduino IDE 1.0 or later.
// Please uncomment below in Arduino IDE 0022 or earlier.
//#include <EthernetDNS.h>
// Ethernet Shield Settings
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// If you don't specify the IP address, DHCP is used(only in Arduino 1.0 or later).
byte ip[] = { 192, 168, 2, 250 };
// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("Enter your token here");
//Button Stuff
const int buttonPin = 8; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
// Message to post
char msg[] = "I'm Tweeting from my Intel Galileo!!";
void setup()
{
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
delay(1000);
Ethernet.begin(mac, ip);
// or you can use DHCP for autoomatic IP address configuration.
// Ethernet.begin(mac);
Serial.begin(9600);
Serial.println("connecting ...");
}
void loop()
{
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is Low:
if (buttonState == LOW) {
// turn LED on:
digitalWrite(ledPin, HIGH);
// Post to Twitter:
if (twitter.post(msg)) {
// Specify &Serial to output received response to Serial.
// If no output is required, you can just omit the argument, e.g.
// int status = twitter.wait();
int status = twitter.wait(&Serial);
if (status == 200) {
Serial.println("OK.");
} else {
Serial.print("failed : code ");
Serial.println(status);
}
} else {
Serial.println("connection failed.");
}
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}












