Monday, December 17, 2007

Lego RCX Programming

I have two Lego RCX units sitting around as part of a large Lego collection. When I first got them about four years ago I played with them intensely. I would look at other people's designs online and then spend hours building cool things with them. This was about six months before I started college, where I didn't have access to them at all. Since I graduated, I have my Lego collection again, but I haven't really had time to do anything with them. Until now.

Four years is a long time when you're talking about technology. While I though my RCX units were the coolest thing ever four years ago, they've now lost some of their appeal (due to Lego releasing their second generation NXT based robotics kit, and me getting older among other things). Four years is also enough time to make the serial port virtually obsolete (try finding a modern-day laptop that has one, mine certainly doesn't). Of course, a serial port is exactly what I needed to connect the IR tower, which communicates with the RCX, to a computer. Luckily, I was able to find a USB to Serial adapter at Fry's for $25.

After hooking everything up and installing the Lego software, I was reminded of how outdated it was when I saw the unskippable intro movie with the terrible compression and the lame 3D graphics that was considered cool back in the day. Even four years ago, I felt Lego's programming language and IDE was overly simplistic, meant more for the 8-14 age group. Now, after three years of school to get a CS degree and half a year of working in the industry, there was no way I was going to program my RCX by dragging brightly colored blocks around, listening to a voice guide me through the tutorials, and watching that cheesy intro movie every time I wanted to edit my program!

Thankfully people have made several of their own languages for programming the RCX. NQC or Not Quite C is one such language based on a simplified version of C. I was surprised to find that the nqc binary not only lets you compile and download programs to the RCX, it also lets you sent raw commands via IR, which basically allows to remotely control everything about the RCX if you know the right opcodes! Good thing someone has compiled a list of opcodes.

As an added bonus, nqc is a command line program, so it can easily be called from other programming languages, like Java, my language of choice. This definitely opens up a whole slew of interesting possibilities.

No comments: