legoAIM

Overview

   Meeting at my house for my school's robotics club did not go as planned, only one person showed up. We worked on a bot for a bit, but then we drifted into other activities. That day I had rereading a wonderful book that I received for Christmas one year on advanced Lego NXT programming, so I got the old brick out and we got to hacking. We played around with some bluetooth stuff, almost got a simple hack working to hijack other bricks nearby, but sadly I don't own another one of them so we couldn't test it out. At some point we had nothing left to do with it, and after a bit of thinking came up with this crazy project.

   I read the section in my NXT programming book about the I2C interface. It occurred to me that I could easily hook a microcontroller to an NXT cable, write some code, and get two way communications going. With that ability the options are almost limitless. I've been doing a lot of stuff with keyboards (synth project), so naturally I wanted to try and hook one up to the NXT using a microcontroller intermediary. I told my idea to my friend and within a few minutes we had set the project goal at nothing less than the functionality of a basic AIM client on the NXT. Technically this project is not really anything as complex as that sounds. The real client sits on a desktop computer. It does all the hard work. The NXT just communicates to it over bluetooth, allowing you to type messages and see replies away from the computer. Might be a nifty thing to have by your bed or on the kitchen counter, but its immediate practicality ends there.

   The things that we are creating in this project open a huge variety of possibilities. Easily set up communication between a microcontroller and the NXT allows a huge variety of interface options. Keyboard input opens the possibility of writing programs for the NXT on the actual NXT itself, with no need for a computer. The bluetooth interface code that we have set up makes it easy for complex control programs to be written on a PC for the NXT, and allows the powerful capabilities of a desktop or laptop computer to be funneled into the otherwise limiting environment of the NXT brick.

To Do

  • Get microcontroller talking to PS2 keyboard.
  • Get microcontroller talking to NXT.
  • Get keyboard data into NXT.
  • Get chars from keyboard into a string in NXT.
  • Solder keyboard interface board.
  • Get Processing bluetooth library talking to NXT.
  • Find a Java AIM client or library with source, and works.
  • Modify AIM library to work with Processing.
  • Communicate over AIM using a program written in Processing.
  • Get NXT talking over AIM using Processing program.
  • Write GUI for NXT AIM client.
  • Create attachment for NXT brick on keyboard.

Timeline


11/8/09 (5:45 PM)-Came up with basic idea for NXT AIM client with PS2 keyboard input.
11/13/09 (7:00 PM)-Researched some possible techniques for connecting PS2 keyboard to Atmega168 microcontroller to NXT.
11/13/09 (8:12 PM)-Compiling, flashing, and testing I2C code for Atmega168 microcontroller.
11/13/09 (8:57 PM)-Too sissy for mega168. Something is up with my programmer/code/wiring. Falling back on Arduino.
11/13/09 (9:15 PM)-Breadboarded circuit to interface PS2 keyboard with Arduino. Struggled to get some PS2 code working from the Arduino playground. Keyboard.present() IS EVIL! Sliced up NXT cable for the I2C interface. Giving up for the night.
11/14/09 (10:04 AM)-Finally have PS2 keyboard reliably connecting and talking to Arduino.
11/14/09 (11:30 AM)-Found a project where a guy (or girl) very successfully connected an Arduino to an NXT. They posted source code, so I'm going to set about tearing it apart. So far it looks like it allows the NXT to control the Arduino and get data from it. Problem is that there is no simple way to send character data.
11/14/09 (11:45 AM)-The code is definitely going to work, just need to figure out what I can throw away and what I should keep. Should be a simple matter to modify the chunks of code that send analog data to the NXT from the Arduino so that they send character data instead.
11/14/09 (12:13 PM)-Not having an easy time with this code. Every time I think I have it figured out I start deleting big chunks of code and then when I test it everything stops working and I have to start all over again. Already on my 3rd try.
11/14/09 (1:03 PM)-FINALLY! It took 6 tries, but now data is flowing from the Arduino to the NXT over I2C. Next step is to add code for PS2 and try not to break everything.
11/14/09 (5:18 PM)-It works! I type a letter on the keyboard, and I see it on the NXT screen. Makes me so happy.
11/14/09 (6:36 PM)-Just fiddling with the code now. Trying to get delay time down. Still takes a few tries to get the key press to register on the NXT. Might need to rethink the relationship between the devices a bit.
11/14/09 (7:12 PM)-I've got keypresses being stored in an array. Full
11/14/09 (7:46 PM)-Banned from computer for rest of day. Need to see some daylight and get some exercise. Project nearing AIM interface stage.

Materials

Obtained?ItemCost
YesLego NXT brick$122.98
YesArduino$29.95
YesNXT Connector Cable$9.99
YesPS2 KeyboardFree

Media

Nothin' yet.

Credits

-Owen TruebloodCode-fu. -InterwebsThe knowledge. -http://rostrich.selfip.net/I2C_NXT_Arduino_2/Excellent NXT<->Arduino interface. -http://www.arduino.cc/playground/Main/PS2KeyboardPS2 Keyboard to Arduino code. -http://en.wikipedia.org/wiki/Lego_Mindstorms_NXTNXT cable pinout.