Remote Twitter

Seniors at Lafayette College take a course entitled Senior Design. It's a shockingly creative name. Snark aside, the class is wonderful. The course is very lab-heavy (the lecture ties up loose ends, but isn't as rigorous as a typical class).

Over the course of a semester, groups of two implement a stripped-down version of WiFi based on the professor's specifications. We're given a radio transmitter / receiver, and are left to design the rest of the link.

WimpFi consists of a few layers. The most physical - the actual radio link - is a 230MHz carrier. (The antenna is driven directly from a differential pair of the FPGA we design on.) Transmissions are BPSK-encoded, which means that a '1' is transmitted as cos(x), and a '0' is transmitted as -cos(x).

Prior to transmission, all data is Manchester encoded. Manchester encoding provides a clock transition in the middle of every bit period, allowing for constant receiver synchronization. (Without Manchester encoding, clock skew between a transmitter and receiver will mangle long packets.) In our system, a logical 1 is encoded as '10' and a logical 0 becomes '01'.

Protocol is the next layer down, but it's sort of complicated and not actually what I meant to write about.

Instead, lets talk about Twitter. And these radios. The radios are designed to send and receive packets of up to 255 bytes. There's a big screen hung on the wall with an always-on receiver, so once I had the transmitter and receiver working in lab, I was looking for something interesting to put on the wall. Twitter seemed a natural choice. I could use a hashtag to filter tweets carefully, and the character limit ensured that my transmissions would fit into the receiver's buffer. (I also considered setting up a weather forecast or beaming ASCII art, but realized that I could do both through Twitter.)

It turns out that the Twitter API is complicated. Searches themselves are a cinch: you just GET a URL sculpted to your search. Not unlike a Google search with But Twitter requires authentication, too. After jumping through a few too many hoops, I got a Twitter API key and found a Python library for Twitter.

It's a somewhat complicated process: Twitter uses something called OAuth for authentication. As I understand it, it allows applications to authorize third party users without accessing their login credentials directly. (The same sort of schtick as when you log into a site using your Google account.)

To use it, you need to grab an API key from Twitter, then figure out how to interface that with your own code. I decided to use Python (cause its easy) and ran through a few Twitter libraries before finding one that (gasp) worked. From there, everything was pretty easy. The script I wrote scraped Twitter every two minutes for a particular hashtag. The returned tweets were compared by unique ID to those already displayed. New ones were sent, in chronological order, to the serial port. From there, the radio board broadcast them across the room to appear in yellow letters on a huge TV on the wall.

Pretty cool.

As usual, the source is attached below. It requires the Birdy Twitter library and PySerial to work. As less-usual, I don't have any pictures of this thing.