3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

simpleTweet_01 python

simpleTweet_01 python
Arduino Python Twitter (Windows)

In this instructable we'll modify my simpleTweet_00 and rewrite the Processing code with Python. You can expect an ignorant walkthrough by an illiterate noob, but maybe that's just what you're looking for.

Before you begin:
If you need help installing Python, navigating Windows from the Command Prompt, or installing packages, then take a look at my instructable How to install Python packages on Windows 7 . It's a quick and dirty walkthrough but it should get you going asap.

And because simpleTweet_00 already explains the concept, I'll be brief:  Arduino sends a message via Serial to Python; Python sends a tweet. The idea here is to create a simple Arduino Python Twitter communication. For beginners.

Let's do it.
 
Remove these adsRemove these ads by Signing Up
 

Step 1Concept

Concept
The idea for this project was to develop generic code allowing you to automatically generate tweets based on input to your Arduino. This example uses a magnetic reed switch, which is your basic on / off switch. You can use this code as is for any two-state switch or modify it for more diversity.

We attach the magnetic reed sensor to my office door and door-frame. A wire runs from the magReed sensor to a pin in the Arduino circuit. Arduino watches that pin's status, HIGH or LOW, and when the status changes from one to the other Arduino reports on that change through Serial(). The Python sketch picks up the Serial() call and checks to see if the current state is the same as the last one posted to Twitter. If the two states are the same then it will not post, but if the new state is different from the previous state, then we're in business.

Python uses python-twitter and OAuth to post the new state to your Twitter account. Done and done.
« Previous StepDownload PDFView All StepsNext Step »
18 comments
Feb 20, 2012. 1:39 PMalexforey says:
Uh oh. It's not working for me. This error makes me think that the python-twitter's not installed properly, but I think it is...

Traceback (most recent call last):
File "D:\Arduino\Projects\twitter.py", line 8, in
import twitter
File "D:\Arduino\Projects\twitter.py", line 16, in
api = twitter.Api(consumer_key='imnotposingthishere',
AttributeError: 'module' object has no attribute 'Api'
>>>
Jun 28, 2011. 3:14 AMDominion-Network says:
Ignore my last comment I missed a step, I've got it working now, but I have a different issue.

running... simpleTweet_01_python
arduino msg: Closed door

Traceback (most recent call last):
File "C:\Users\XXX\Documents\Python\Tweet", line 45, in
listenToArduino()
File "C:\Users\XXX\Documents\Python\Tweet", line 22, in listenToArduino
compareMsg(msg.strip())
File "C:\Users\XXX\Documents\Python\Tweet", line 29, in compareMsg
pM = ""+prevMsg[0]+""
IndexError: list index out of range
Jun 30, 2011. 1:12 AMDominion-Network says:
I ended up writing my own python code, a lot simpler, it works, but I'm getting my magnetic reed switch today, what other components will I need to set this up?
Jun 25, 2011. 12:40 AMcris3D says:
not works..

File "C:\Documents and Settings\crystal\Desktop\tweet2.py", line 37, in postMsg
tweet = api.PostUpdate(newMsg+", "+localtime)
File "build\bdist.win32\egg\twitter.py", line 2766, in PostUpdate
data = self._ParseAndCheckTwitter(json)
File "build\bdist.win32\egg\twitter.py", line 3668, in _ParseAndCheckTwitter
self._CheckForTwitterError(data)
File "build\bdist.win32\egg\twitter.py", line 3691, in _CheckForTwitterError
raise TwitterError(data['error'])
TwitterError: Timestamp out of bounds

I followed all steps, packages installed correctly (I guess), I use XP .. well.. I'm not a Python User.. but your application is really interesting :)

thanks for your efford!
Jun 25, 2011. 1:34 PMcris3D says:
I test those codes and...


the first print..

now: Sat Jun 25 13:24:10 2011

works!

the second..

>>> ================================ RESTART ================================
>>>

Traceback (most recent call last):
File "C:\Documents and Settings\crystal\Desktop\test.py", line 11, in
tweet = api.PostUpdate(newMsg+", "+localtime)
File "build\bdist.win32\egg\twitter.py", line 2766, in PostUpdate
data = self._ParseAndCheckTwitter(json)
File "build\bdist.win32\egg\twitter.py", line 3668, in _ParseAndCheckTwitter
self._CheckForTwitterError(data)
File "build\bdist.win32\egg\twitter.py", line 3691, in _CheckForTwitterError
raise TwitterError(data['error'])
TwitterError: Timestamp out of bounds

:'(
Jun 28, 2011. 11:12 AMcris3D says:
Sure, I read your HOWTO and install python packages, but.. I will try to re-install the twitter package, I'll let you know ,

thanks for all!
Jun 28, 2011. 7:25 PMcris3D says:
noup, I guess my PC not works.

I tried to run the processing sketch and works in anoter PC.. but in my PC not!

thanks for your attention.. I'll try in laptop when I have it..

saludos!
Jun 25, 2011. 10:10 AMcris3D says:
so quick! I will try this on Monday, and I'll let you know the results..

thanks for your attention!
Jun 23, 2011. 10:12 PMsheetmetalalchemist says:
This is totally the way to go to get an arduino tweeting under linux. So much simpler. One thing that may be handy to point out...there is no COM4 if you are running *nix! Replace COM4 with /dev/ttyUSB0 or whatever is listed in Tools > Serial Port in the arduino IDE!
Jun 16, 2011. 11:05 AMLayout says:
I can't believe I've been a member for four years and I hadn't realized until I saw your comment that I can click the "i" in the corner of the image to see a larger size image. Thanks for that.

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
5
Followers
4
Author:pdxnat