![]() |
![]() |
Getting Started on Linux
|
Getting Started on Linux
This version of the tutorial is for the 0.9 release of leJOS NXJ. PrerequisitesJava Development KitYou will also need a Java Development Kit (JDK) on your PC. Note that a Java Runtime Environment (JRE) is not sufficient as it does not allow you to compile Java programs. You can download the latest JDK from http://www.oracle.com/technetwork/java/javase/downloads/. Follow the instructions for installing it. leJOS NXJ works has been tested with JDK versions 1.5, 1.6, and 1.7, and will not work with earlier versions. JDK 1.6 or 1.7 is recommended. Note that leJOS has only been tested with the official Oracle JDK. It is likely to work with the Open JDK, but not with gcj. leJOS NXJ needs to know the locations of java.exe and javac.exe. There are several possibilities
to achieve that: (1) add the bin directory of the JDK to your PATH environment variable
so that commands such as USB DriverIn order to use a USB connection to your NXT brick on Linux, libusb must be installed. It can be obtained from http://libusb.sourceforge.net. It is pre-installed with many Linux distributions, or is available as an optional package. You will need to ensure that the packages that leJOS NXJ is dependent on are on your system. To build the jlibnxt JNI library, which is used for USB access, you need the Development files for libusb. The package is usally called something like libusb-devel. Note that either libusb-0.1 or libusb-compat is required. The newer libusb-1.0 will not work. If you are running leJOS NXJ from a non-root user, you will need to ensure that you have read and write access the NXT USB device in /dev/bus/usb. You can temporary allow access to certain USB decives using the following command:
The A better solution is to use udev rules. How to do this may vary with different Linux systems. To use udev rules, set up a file such as /etc/udev/rules.d/70-lego.rules and populate it with the following lines:
These rules rely on your username being in the lego usergroup. You may have to create
this usergroup via BluetoothIf you want to communicate with the NXT over Bluetooth, you will need a Linux supported Bluetooth dongle or built-in support on your PC. leJOS uses the Bluecove libraries which are included in the distribution. You can use leJOS NXJ without Bluetooth. Installing leJOSDownloading the softwareYou can download the leJOS NXJ software from The leJOS NXJ download page. The Linux edition of leJOS is distributed as a .tar.gz file. Untar the archive to a location of your choice, e.g. /opt/leJOS_NXJ Setting up environment variablesleJOS NXJ needs to know the locations of java.exe and javac.exe. There are several possibilities
to achieve that: (1) add the bin directory of the JDK to your PATH environment variable
so that commands such as Furthermore, the NXJ_HOME variable should be set to the directory where leJOS NXJ is installed. It allows other applications, e.g. the Ant scripts, to locate the leJOS Development Kit. Also, for easy exececution of the leJOS commands on the command line, the bin folder of the leJOS distribution should be added to the PATH variable. Examples:
The bin directory for the JDK may already be on your PATH. In that case, it is unnecessary to set LEJOS_NXT_JAVA_HOME or JAVA_HOME, unless you want to have multiple JDKs on your system and want to select a specific JDK for use with leJOS. With most Linux distributions, you can set these environment variables for the current user in .bash_profile or for all users in /etc/profile. Building the releaseIn order to use USB communications, you have to build the java native library first.
In order to do that, change directory to $NXJ_HOME/build and type Flashing the FirmwareAs leJOS NXJ is a firmware replacement, you will need to flash the firmware to your NXT. Note that this will overwrite any existing firmware. If you have the standard LEGO firmware or other third-party firmware on your NXT, existing files will be lost. Note that the 0.9 release changes the amount of flash memory reserved for the firmware and the startup menu, so when you first flash the 0.9 firmware any existing files will be lost Make sure your NXT is attached to the PC via USB cable and switch it on by pressing the
orange button. Open a command line prompt and either type the command If you chose If you chose Note that at the time of writing, the LEGO firmware has serious problems with talking to a computer running Linux via USB. Therefore it is recommened to manually put the NXT brick in firmware update mode as described above. The leJOS firmware does not have any problems of that kind. Testing your InstallationYou can test your installation by following the steps for writing your first leJOS Program which are the next part of this tutorial. |
|