The NXT and Linux
This page is work in progress.
The first version should be complete in April 2008.
See the Lego Project page for more information.
In order to controll or program the NXT we have to be able to connect to it. This can be done over USB or Bluetooth.
I am using kupuntu for development, so most software install commands and paths you see may be specific to ubuntu based systems.
Setting up USB
You will need libusb installed on your system. On ubunutu it was a matter of installing the libusb package. As we will need the headers for it later too, this was a simple.
sudo aptitude install libusb-0.1-4 libusb-dev
I also created a udev rules file /etc/udev/rules.d/70.legonxt.rules which I got from NBC/NXC site:
SUBSYSTEM=="usb_device",ACTION=="add",SYSFS{idVendor}=="0694",SYSFS{idProduct}=="0002",MODE="0666"
This will make sure that you as a user have enough rights to communicate with the NXT.
Setting up Bluetooth
(This is all still in flux as I am just starting/trying to understand it myself)
Make sure your bluetooth device is working.
You will need bluez installed. On my system I just made sure that the bluez-utils were installed. This was simple to install:
sudo aptitude install bluez-utils
Turn on your NXT and enable the bluetooth on it in discover mode(visible). Now you can scan for your NXT by running:
hcitool scan
you should see something like:
Scanning ...
00:16:53:05:7A:1E NXT
If not, your NXT's bluetooth is not on or not set to visible. The numbers you see before the NXT is your NXT's MAC address, you will need it later.
Next we want to pair our NXT with our computer.
Once we let the NXT connect to the computer we need a passkey agent to take care of the pairing.
It will create/update the file
/var/lib/bluetooth/xx:xx:xx:xx:xx:xx/linkkeys.
The xx:xx:xx:xx:xx:xx is the MAC address of your machine's bluetooth device.
In a shell run:
passkey-agent "echo PIN:1234" 00:16:53:05:7A:1E
Make sure you use your NXT's MAC address and not the one above.
Go into the bluetooth settings of the NXT and select the search option. Let the NXT search and find your machine. Your machine must be visible(in discover mode). If the NXT has found your machine, press the orange button twice. The NXT will ask you to accept a PIN which defaults to 1234. Just accept it by pressing the orange button. The passkey-agend should finish with a message like Passkey service has been released.
I got a Line Busy on my NXT, but we can ignore this for now.
Make sure the file
/var/lib/bluetooth/xx:xx:xx:xx:xx:xx/linkkeys was created.
Alternatively to using passkey-agent you can use GUI tools like KBluetooth or Gnome's bluetooth applet, ... They will ask you for a PIN when the NXT tries to connect with your machine. They will also help you configure your bluetooth device so that it is discoverable ...
That is it, your NXT and computer are paired.
Flashing the NXT
To load a new firmware onto the NXT I used libnxt.
Building libnxt was done using scons and just worked.
Once built you upload a new firmware by using:
sudo ./fwflash path_to_firmware.rfw
It should be possible to run the comman without sudo. Once I figure out what I have done wrong with dev-rules or permission, I will update it.