Unexpected Animal Stories Keyboard

Last Saturday, Socialbomb held its first Hack Day.

I had two goals for Hack Day: (1) get a PS/2 keyboard talking to an Arduino and (2) make something interesting with processing.py. Here’s the end result (make sure to click through to the full-screen version for maximum legibility):

Crazy Animal Stories Keyboard from Adam Parrish on Vimeo.

It’s the Unexpected Animal Stories Keyboard, a keyboard which intermittently replaces whatever you’re typing with an Unexpected Animal Story.

It turns out that the part of this project that I thought would be difficult turned out to be easy: getting a PS/2 keyboard talking to an Arduino was a piece of cake. I already had a bunch of mini-din connectors; I just soldered one up to a breadboard, hooked it up to my trusty Arduino Diecimila, put the excellent ps2keypolled library in my libraries folder, plugged in the keyboard and voila: keystrokes gettin’ read.

Here's what the setup looks like

globbiest solders since middle school

I’ve got big plans for the PS/2-to-Arduino data chain, involving a data logging chip and shoes made of keyboards and sledgehammers and/or yogurt. But for Hack Day, I just wanted to whip up something fun. So the next step was to get the keystrokes from the Arduino to my computer, preferably into a processing.py sketch. Much to my surprise, Processing’s serial communication libraries worked with processing.py without a hitch*, which left me free to write the tiny little generative text toy that you see in the video above.

The biggest unforeseen timesink: I spent a few hours trying to figure out the best way to send ps2keypolled’s 16-bit key codes from the Arduino to the computer, eventually settling on the stupidest possible ad-hoc protocol that could work (and porting a big chunk of C code to Python to translate the key codes to ASCII). See the source code for more details.

Most surprising happy discovery: processing.py is amazing. Being able to quickly write the text-munging code in Python while still retaining Processing’s built-in functions and easy-to-use libraries is just… a revelation. For a project that’s just a few weeks old, it feels surprisingly polished. If you’ve got Python and Processing expertise, I recommend you give it a go.

Source code for the whole shebang: crazy_animal_keyboard_source.zip

* Okay, there was a single hitch. Apparently, the serial communication library included with Processing (and, therefore, processing.py) doesn’t support 64-bit Snow Leopard (as documented e.g. here). I was able to get around this without problems by using the -d32 parameter to the java runner, i.e.

$ java -d32 -jar processing.py animal_keyboard.py

Tags: , , , , , ,

  1. Jonathan Feinberg’s avatar

    I am so happy to see this. I believe it’s the first use of I ONCE SPREAD SOME ECHIDNAS ON A TOASTED BAGEL. Just out of curiosity: I noticed you wrote a small part of the project in plain-old PDE. Was there no way to get that part to work in Python? I envision Pyduino.

  2. adam’s avatar

    Jonathan, yeah, the PDE is the Arduino program. (All it does is read the keystroke from the keyboard and send it over serial to the computer.) And yes, Pyduino would be amazing.

Reply