a’twittering Arduino without an Ethernet shield

The Arduino Ethernet shield is pretty awesome and can, for example, allow a mini webserver to run off the board displaying sensor data. Although not outrageously expensive, at $45, it’s still $15 more than an Arduino Uno itself. There does seem to be quite a bit of functionality that you can do with it, especially as the official Arduino Ethernet shield includes a micro SD slot allowing to read + write data to card, but for my tinkering right now, it’s a little too much money.

But, it would be cool to at least look at how to push data from the Arduino out the Internet, and so I started looking around at ways to utilize the USB connection and have the computer the Arduino is connected to act as a go-between. Cue some fun python libraries. The setup entails using pySerial to monitor the USB port and read in data printed to the Arduino serial port, and then python-twitter to push that data out as a status update to twitter. This was all based off an awesome post from Brad Wells on using Arduino to Twitter over USB.

To get the python libraries installed and ready to roll:

  • Download pySerial – unpack the archive and then from the command line within that directory run
    python setup.py install
  • python-twitter has three dependencies that need installing first:
    • simplejson – download and unpack the archive, and then from the directory run
      python setup.py install
    • httplib2 – download and unpack the archive, and then from the directory run
      python setup.py install
    • python-oauth2 – download and unpack the archive, and then from the directory run
      python setup.py install
  • Now you can download python-twitter – unpack the archive, and then from the directory run:
    python setup.ph build
    python setup.ph intall

Now we need to get twitter ready. The python script uses the twitter API, so it requires you to register your own application in order to get the access tokens needed to function. Most people create a separate twitter account specifically for the Arduino to tweet to (the entry in the Arduino playground for tweeting using the Ethernet shield has you running through an external service to pass the tweet, so you probably shouldn’t use your primary account), and when registering your application at dev.twitter.com, make sure you’re signed in to twitter using this dedicated Arduino account. After registering, your consumer key and consumer secret key are immediately provided – click on ‘My Access Token’ to gain the access token and access token secret.

The python script, broken down and detailed in Brad’s blog post, requires you to copy and paste those four twitter tokens in to the script. On the Arduino side, the sketch can be as simple as:

Serial.begin(9600);
Serial.println("Tweeting arduino!");

within setup(). All you need to do is initialize a 9600 baud serial instance and then print out a line. Whatever your print out to the serial port is what the python script will read in and tweet. Make sure you compile and upload the sketch to your Arduino before you run the python script – as you have python monitoring your USB port to watch for the serial output, you can’t then upload via USB to the Arduino. Once you sketch is uploaded, you can fire up the python script and then hit the reset button on your Arduino.

Tweeting Arduino

The python script will just sit at the command line, watching for messages sent out to the Arduino’s serial port. If you check your twitter feed, you should see your tweet 🙂 You can easily expand beyond simply printing a line of text to reading in data from sensors and have that included. It would definitely make it more useful, and within the python-twitter library, there are functions to also monitor twitter updates and send data back to the Arduino. That’s something I haven’t quite figured out yet, but is definitely an appealing feature!

About

Senior Content Development for Microsoft writing about Azure virtual machines. Occasionally I play video games.

Posted in ardunio, internet, my projects
0 comments on “a’twittering Arduino without an Ethernet shield
2 Pings/Trackbacks for "a’twittering Arduino without an Ethernet shield"
  1. WordPress 2.8.4

    […] "ER…HO. HO. HO." — Death makes a career move (Terry Pratchett, Hogfather « a’twittering Arduino without an Ethernet shield […]

  2. PHP

    […] users there’s no extra cost – so give it a whirl, follow Ian’s instructionsand get yourself a twitter account. Then you can also follow us […]

Leave a Reply

Your email address will not be published. Required fields are marked *

*

About Me

Iain Foulds, 32 years old. Originally from England, now living in Seattle, WA. I currently work as a Senior Content Developer for Microsoft writing about Azure VMs. Gamer. Very passionate about photography. Comments and opinions expressed here are my own. More...

Categories

Archives