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.

7 comments:

AF said...

Hi Robert - been scouring the net and came across your post. Did you ever get it to work for mac? I'm about to pick up one of the nike+ipod adaptors to listen for foot pods from my sensor with the intention of using it to translate each footfall into a midi note on my mac. Any idea how to make this work? If you know how I'd really appreciate the help - you can email me at adam at wisemonkeyrecords dotcom - Cheers!

Robert said...

I did get it working on my Mac mini, but it's been awhile. I'll take a look at it this evening, and see what I find.

AF said...

Awesome! How did you go?

Jisoo said...

Hi,
Could you let me know if there is any tip in getting data into Mac?

I'm going to try out soon but a little scared since I'm a newbie in programming (xcode, java) and don't at all about Perl.

Any comments and advice is welcome - my email: avignon96 at gmail dot com

Boris said...

Here's a python version (works for Mac) for establishing a connection with Nike+: http://www.borismus.com/nike-hacking-with-python/

Robert said...

Boris, that's awesome. I'm going to link to your site from this post on my new site http://roberttadlock.com . People are always asking me for a Python implementation.

Boris said...

Thanks Robert!