WiiMote IR Camera with Lego NXT Brick – LeJOS

This previous post talks about how to connect a IR Camera from a WiiMote to an Arduino.

There’s also this one, talking about how to connect it to the .NET micro framework, FEZ Domino board (which also has hardware details on how to extract the mentionned camera and solder it on its own little board…).

It’s therefore time I wrote a quick post, on how to interface this wonderful camera with a Lego NXT Brick, programmed in Java thanks to LeJOS !

WiiMote IR Camera and Lego NXT - LeJOS

IR LED Tracking

Hardware

Using the previously created board for the IR Camera, BUT it turns out (after a few frustrating hours…) that the two 2.2KOhms pullup resistors on the I2C bus are too much !

The NXT (you can google it up for more details) is slightly peculiar on its I2C requirements, in that the pull up resistors have to be quite high in value (82KOhms – from the docs). This is apparently because it has some 4.3KOhmns internal resistors of its own, in order to protect the ports.

So I’ve cut out the original resistors of my board (it turns out the Arduino can read the camera fine without them anyhow…. Arduino is reaaaaly great in its simplicity and tolerance ! Never managed to burn one, it’s not fussy with its I2C bus, etc. …) and soldered two 100kOhms ones….

Update 10.06.2011 : After more tinkering due to interference between the I2C bus and some close by motors, I managed to lower the pullup resistors to 33kOhms. Below that (tested with 20kOhms) it doesn’t work anymore… The lower the value, the more reliable the line apparently. Add to this the change in speed to 100kHz instead of 400kHz and here we have a less error prone bus.

I also had to move the board to a different port than the one on which the slave Arduino board is, but more on this later, once I will have investigated the issue…

Software

Here’s the Java / LeJOS class that reads the data from the WiiMote IR Camera.

The only tricky thing worth mentionning regarding porting this code from Arduino to Java, is that in Java bytes are signed, so you need to do the _dataBuff[i] & 0xFF trick to unsign them…

You have 3 classes:

IRCamera.java – the main one that communicates through I2C with the camera

PID.java – a simple implementation of a PID control algorithm

FollowBehaviour.java – a behaviour class that gets activated when the camera sees something and tries to track that object…