I'm trying to do a simple control of an arduino using twitter. The arduino would be connected to a laptop and be able to make and led go high or low with the simple tweeting of "led on" or "led off"
What is the best way to go about this? I've been looking at all kinds of options, code examples are much appreciated.
Controlling Arduino With twitter
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- richms
- Posts: 558
- Joined: Tue Jan 20, 2009 3:05 am
Re: Controlling Arduino With twitter
I briefly tried using twitter to go the other way, and something I kept running into was twitters refusal to take something if I had already tweeted it recently, Oops you already said that from the web interface and something else from the API. Adding a timestamp solved it.
Something to keep in mind if you are planning on simple commands like LED on and LED off.
Something to keep in mind if you are planning on simple commands like LED on and LED off.
-
- Posts: 2
- Joined: Tue Dec 28, 2010 12:14 am
Re: Controlling Arduino With twitter
yeah there are tons of projects on how to post TO twitter, but i want to read FROM twitter
- jdubrow
- Posts: 32
- Joined: Tue Dec 21, 2010 1:49 pm
Re: Controlling Arduino With twitter
I would write a piece of software on the computer* to query twitter peridically for the twitter 'channel', then serer that up on your webserver, then put an ehternet connection on your arduino then have it query your web server.
* I would do it this way so if twitter updates you don't have to reprogram your device to understand how twitter works (or does it have an RSS feed?)
* I would do it this way so if twitter updates you don't have to reprogram your device to understand how twitter works (or does it have an RSS feed?)
-
- Posts: 16
- Joined: Wed Apr 28, 2010 8:34 am
Re: Controlling Arduino With twitter
Accepting commands from Twitter is a great idea. In general, you'll need to use a program on your computer to listen to Twitter, to parse the status updates, to scan those updates for keywords, and to pass those keywords to Arduino through Serial port write commands. I've got two projects that do all that except for the final step of writing back to Arduino. I have other projects written in Processing that do it, and I can dig 'em out if you like, but you may have already found examples.
- jchristensen
- Posts: 111
- Joined: Mon Jan 03, 2011 11:45 am
Re: Controlling Arduino With twitter
An Arduino/Twitter project was featured in the June issue of IEEE Spectrum:
http://spectrum.ieee.org/geek-life/hand ... ice-door/0
http://spectrum.ieee.org/geek-life/hand ... ice-door/0
-
- Posts: 16
- Joined: Wed Apr 28, 2010 8:34 am
Re: Controlling Arduino With twitter
And here is the Tweet-a-Pot, an Arduino Python project that accepts commands from Twitter to control a power supply.
It uses Python on the computer to interact w/ Twitter, though you could do this with Processing, Java, etc.
It uses Python on the computer to interact w/ Twitter, though you could do this with Processing, Java, etc.
-
- Posts: 16
- Joined: Wed Apr 28, 2010 8:34 am
Re: Controlling Arduino With twitter
Here is your answer:greggawatt wrote:I'm trying to do a simple control of an arduino using twitter. The arduino would be connected to a laptop and be able to make and led go high or low with the simple tweeting of "led on" or "led off"
What is the best way to go about this? I've been looking at all kinds of options, code examples are much appreciated.
I've posted an example I call the Twitter Mention Mood Light up on instructables that allows Twitter to command the LED on your Arduino. I even wrote it twice, once in Processing and once in Python.
Specifically, it uses the Processing or Python code to check Twitter ever 15 seconds for any mention of @yourUsername. Upon finding a mention, the Processing or Python code sends a message to Arduino through the Serial.write() command. Arduino evaluates the message and if the message meets certain criteria then Arduino tells the led light to blink.
Visit Twitter Mention Mood Light for complete details, but here are a few highlights:
Arduino code for receiving messages over Serial:
Code: Select all
void setup(){ // begin
Serial.begin(9600);
}
void loop(){
listenToSerial();
}
void listenToSerial(){ // Twitter commands enter here
int serialMsg = 0;
if (Serial.available()){
serialMsg = Serial.read();
if (serialMsg == 1) state = "mention"; // processing
if (serialMsg == 49) state = "mention"; // python
}
}
Code: Select all
import processing.serial.*; // this appears near top
Serial arduino; // near top, sets "arduino" equal to action known as Serial
void setup() {
println(Serial.list()); // do this to learn what ports to use
String arduinoPort = Serial.list()[0]; // Set the Serial Port here
arduino = new Serial(this, arduinoPort, 9600); // Activate the Serial Port connection here
writeToArduino();
}
void writeToArduino(){
arduino.write(1); // The Arduino receives a 1
}
Code: Select all
import serial
arduino = serial.Serial('COM4', 9600, timeout=1)
def writeToArduino():
arduino.write(1)
while 1:
writeToArduino()
Hope that helps!
Please be positive and constructive with your questions and comments.