In this article I will be setting up the NBC/NXC compiler for use on Ubuntu Maverick (it should work on most current *nix releases, too - if not, please comment and we'll look into it).
The first thing to do is make sure the NXT brick is recognised by the system. To do this we run:
david@pinatubo:~$ lsusb|grep Lego
Bus 002 Device 002: ID 0694:0002 Lego Group Mindstorms NXT
david@pinatubo:~$
If you get similar output, you are ready to go onto the next stage. If not, then there is probably a misconfiguration or fault somewhere in the USB communications, or the brick isn't turned on.
To be able to compile and download NXC or NBC programs, all you need is the nbc executable. Download the latest release from here and untar. Make sure the binary is executable by cd'ing to where you untarred it and run chmod +x nbc. You can now run it by typing ./nbc at the terminal. This isn't very convenient unless you happen to be in the directory whenever you need it. I prefer to move the compiler to /usr/local/bin/ so it is on the system include path and the './' can be omitted.
david@pinatubo:~/nbc$ ls
nbc
david@pinatubo:~/nbc$ sudo mv nbc /usr/local/bin
[sudo] password for david:
david@pinatubo:~/nbc$ which nbc
/usr/local/bin/nbc
david@pinatubo:~/nbc$
You can now compile and download NXC and NBC programs by running:
david@pinatubo:~/nbc$ sudo nbc -d -EF test.nxc
[sudo] password for david:
david@pinatubo:~/nbc$
Flags used are -d to make it download the compiled binary and -EF to tell it to compile it for the enhanced firmware (see nbc download link). For a full overview of available options, run nbc -help.
You may have noticed that the compiler needed to be run as superuser in order to work. This is due to the way Linux handles device files and a udev rule will need to be made to let it run at normal permissions. udev is the utility in charge of dynamic devices (e.g. USB devices which must allow hotplugging) on Linux systems. When a new device is connected, it looks through a set of predefined rules to tell it what to do with the device and who is allowed to access it. The details of how to set up the necessary udev rule are a tad too long to include here, but there are excellent instructions here on the NBC website.
That should be enough to get the NXT brick talking to your Linux box. If there are any errors or omissions, or you have problems following these instructions or configuring your system, please comment below and we will try to help.
Not got one? Buy LEGO Mindstorms NXT 2.0 (8547)