Wednesday, January 6, 2010

RC Sensor for Mindstorms NXT

Well its done... mostly.

The previous RC - Lego IR converter naturally progressed into this. Instead of converting to IR, which is then received by a third party NXT sensor, it made more sense to skip the IR completely and have the radio control receiver interface directly with the NXT.

To that end I had to figure out how to interface the Arduino with the NXT. From everything I had read it appeared fairly straightforward, yet there didn't seem to actually much in the way of documentation on how to do it. Typically people would use a PIC chip to do the conversion, but seeing as I (and a lot of other people) are more familiar with the Arduino it seemed a better way to go, not to mention open up a lot more possibilities later.

The NXT communicates with its sensors via I2C, at first glance it appears a fairly complex protocol, but thanks to the Arduino library it becomes a lot simpler. That didn't mean I was out of the woods yet. While HiTechnic supply pretty much all the information you need to communicate with their sensor, I was trying to mimic it. The point was that while a sensor is all well and good, you need some code on the NXT in order to be able to read data from it. HiTechnic had already released a NXT-G block to access their IR Receiver, I wanted my sensor to be able to use their code.

Its useful because once the arduino is able to mimic the original sensor you are no longer limited in what you can sense. The Lego Power Functions has an Infrared remote that has 4 channels, each channel has 2 motors that can be driven either backwards or forwards, with power being applied being varied between 0 and 100% (or between -100% to 100%)

By replacing the HiTechnic sensor with an Arduino, you gain the ability to let the NXT see 8 analog channels on a single sensor (a pity that the standard Arduino only has 4 analog inputs free when using I2C), not to mention logic on each of those channels (Forward and Reverse).
And thats just using the basic HiTechnic NXT-G block. If you were to start using NXC or some other language you remove even more restrictions.

The reverse engineering would likely not have been possible without a Bus Pirate. While I may have eventually been able to get everything working without it, it made things so much easier and removed a lot less guesswork.

So far I have tested this with a Hitec Electron6 and a Arduino Deumilinove, both being powered by the NXT's 4.3V line.
Unfortunately the 3.3V/8MHz arduinos aren't powerful enough to decode the PPM signal without losing sync. The 5V/16MHz versions work fine. That being said, if your sensor did not require the higher processing power, there is no reason why you couldn't use the 8MHz version.

Code: HERE


The main reason its only "mostly" finished is that I am not happy with the case, its much larger than I know I could get it. But that is going to have to wait until I get my Cupcake CNC machine, this will allow me to print my own cases. I also intend to add a jumper or switch to enable/disable channel mixing, but that's something I'll leave till redesigning that case. The Cupcake is a major project all by itself however, so it will be something to get back to much later.

For my next trick I'm going to try to duplicate the HiTechnic Compass sensor. What makes this more difficult is that the compass sensor is already an I2C device, so the Arduino needs to get the compass heading data and make it available where the software expects it to be. Sounds simple, except that part of the I2C topology is while there may be many slave devices there can only be a single master, and to do what I want to do the Arduino has to be both a master and a slave, making it the second master on the bus. After that is a GPS sensor. Man, I've got a queue forming...

And something I cooked up to make things a little easier when working with the NXT and Arduino:

Its an Arduino shield with NXT socket. I recently started etching my own circuit boards again, the RC sensor and this are a couple of the first boards I've made. The DIP switch allows you connect and disconnect the individual pins to the Arduino as you may want. Along with a couple of rows of header sockets to break out the connections to a breadboard and the like. I've already redesigned it somewhat as I already realised it could be better, but that's normal :P

No comments:

Post a Comment