Skip to main content

Install LeJosRT under Linux

Posted in

This tutorial was realized and tested under a distribution Ubuntu 10.04. It was inspired of Getting Started on Linux.


Prerequisites

 

Java Development Kit

You 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. For that purpose, download and install the following packages as well as their dependencies:

  • default-jdk
  • gcj
  • ant-gcj

 

Package Dependencies

You will need to ensure that the packages that leJosRT is dependent on are on your system. So, in order to use a USB or bluetooth connection to your NXT brick on Linux, download and install the following packages as well as their dependencies:

  • libusb-0.1-4
  • libusb-dev
  • libobexftp0-dev
  • bluez
  • libbluetooth-dev
  • libbluetooth3

 

Accessing USB devices

Set up a file such as /etc/udev/rules.d/70-lego.rules and populate it with the following lines:

# Lego NXT

BUS=="usb", SYSFS{idVendor}=="03eb", GROUP="lego", MODE="0660" 

BUS=="usb", SYSFS{idVendor}=="0694", GROUP="lego", MODE="0660"

This relies on the username you are using being in the lego group. You can modify the file to your requirements.  You may need to reload the rules or restart udev.


Installation

 

Downloading and unpacking the software

Download the software from the download page.

Unpack the release a directory of your choice, e.g. /home/user/

 

Setting up environment variables

With most Linux distributions, you can set these environment variables for the current user in .bash_profile or for all users in /etc/profile. You need to set :

  • NXJ_HOME : The folder you installed leJosRT into
  • JAVA_HOME : The folder where you installed the JDK
  • PATH : Add the bin folders for the JDK and leJOS

For example, in the /etc/profile file, add at the end : 

    export NXJ_HOME=/home/user/lejosRT/lejos_rt

    export JAVA_HOME=/usr/lib/jvm/java-6-openjdk

    export PATH=$PATH:$JAVA_HOME/bin:$NXJ_HOME/bin

You need to restart your session.

 

Building the software

To build the release, change directory to lejosRT/lejos_rt/build and type ant. If you have all the dependent packages installed the release should build without errors.

 

Flashing the firmware

As leJosRT 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 LeJosRT changes the amount of flash memory reserved for the firmware and the startup menu, so when you flash the 0.85 firmware any existing files will be lost

Make sure your NXT is attached to the PC by its USB cable, and switch it on by pressing the orange button.

Type nxjflash to flash the leJosRT firmware. If your NXT is in firmware update mode, the firmware will be updated. You will see some messages on your command window, and the NXT should show the leJOS splash screen and then the leJOS NXJ menu. If your NXT has a previous version of the leJOS or LEGO firmware on it, a list of the NXTs connected to the USB will be shown, and you will be asked to input the number in the list of the NXT you want updated - this will be 1 if a single NXT is connected to your PC. If your NXT has other firmware on it, or if nxjflash fails, you must put your NXT into firmware update mode. Press the reset button (at the back of the NXT , upper left corner) for more than 4 seconds. A straightened paper clip could be useful for this. Your NXT will audibly tick when it is firmware update mode. Then try nxjflash again.


Testing your installation

 

You can check that you have successfully installed leJosRT on your PC and your NXT by compiling and running your first program.

 

Compiling and running your first program

Java programs need to be compiled to class files before they can be run. For leJosRT, all the class files that are to be run on the NXT needed to be linked to produce a binary file (with the extension .nxj) and this must then be uploaded to the NXT.

To run a sample program, such as the View.java sample, follow these steps:

Start a shell session, and change directory to the lejosRT/lejos_rt/projects/samples/View folder:

Compile the program with the nxjc command:

 nxjc View.java

Then link, upload and run it with the nxj command:

nxj -r View

You should see the menu of the View sample on your NXT.