Tuesday, June 2, 2009

Some Perl code for the Nike+iPod serial adapter

The other day, I came across a nice tutorial on using a Nike+iPod adapter as a kind of active RFID to unlock your car doors. I immediately thought of a need that I have to be able to open my garage door while pulling up on my motorcycle. It's kind of a hassle to reach in my pocket and open the door, and why should I have to do that? Anyway, I had a Nike+iPod kit at home that I don't really use, as well as an Arduino, so all I needed to do was buy the adapter from Spark fun electronics in Boulder (my favorite place to spend money). So I put in the order, and in a few days I had the adapter that came with a nice VB app that allows you to immediately plug the adapter into your computer and start listening for "foot pods". The next thing I wanted to do was create a Perl script to listen for the pods so that I could use the adapter on Linux and maybe my Mac. So after a few hours, I have a script that works on Windows, and has successfully worked on my girlfriends Ubuntu laptop, but to date is not working on my Intel Mac mini or my Ubuntu server.

Here are the steps you need to follow to get the script up and running:

1. On Linux/Mac - Install Device::SerialPort using CPAN
a. On Windows - Install Win32::SerialPort using CPAN (make sure to follow all directions. On Windows, it's a little more involved)
b. And install Win32-API using PPM (I use ActiveState, so it has PPM)
2. On the Mac, I needed to install the UART driver from here. It seems as of Kernel 2.6 the driver is included in Linux.

You can download the Perl script (called pod.pl) from Drop.io.

After you get the script, you may need to edit the port that your adapter is running on, and you can figure that out by going to the device manager in Windows, using dmesg on Linux, or using the System Profiler on Mac OS X.

Then just fire up the script, and it will start listening for "foot pods" and dumping out the ID as well as the raw data received from each pod.

I'll be using the adapter with my Arduino soon, and I'll post details on that project, as well as any updates I have on getting the adapter to work on the Mac.