Getting Started on Microsoft Windows
Getting Started on Microsoft Windows

This version of the tutorial is for the 0.9 release of leJOS NXJ.

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. You can download the latest JDK from http://www.oracle.com/technetwork/java/javase/downloads/. Follow the instructions for installing it. leJOS NXJ 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.

leJOS NXJ only works with 32-bit version of the JDK and JRE, so even if you have a 64-bit system, you should select a 32-bit version of the JDK.

USB Driver

To run leJOS NXJ on Microsoft Windows you will need a suitable USB driver on your PC. If you have installed the standard LEGO Mindstorms NXT-G software, a suitable driver (the so-called Fantom driver) is already installed. If you do not wish to install the LEGO software on your PC or if you want to update the Fantom driver to the latest version, you can get an installer from The LEGO Mindstorms site. It is strongly recommended to update to the latest version (1.1.3 at the time of writing).

It has come to our attention, that NXT-G as well as the Fantom driver don't install under Windows 7 Starter Edition. This can be worked around by adding a line to the setup.ini file. Here you find the official instructions by National Instruments, the authors of NXT-G and the Fantom driver. In short, you have to add AllowWindowsStarter=1 to the [OS]-section of the setup.ini file.

Bluetooth Stack

If you want to communicate with the NXT over Bluetooth, you will need a Bluetooth dongle or built-in support on your PC, and a Bluetooth software stack. leJOS NXJ has been tested with the Microsoft and Widcomm stacks, but might also work with others. Bluesoleil is known to cause problems. You can use leJOS NXJ without Bluetooth.

Back to top

Downloading the software

You can download the leJOS NXJ software from The leJOS NXJ download page.

It is recommended that you use the Windows installer, but there is a ZIP file release that you can use if you prefer to do a manual installation.

Back to top

Running the GUI installer

Download leJOS_NXJ_0.9.1beta_win32_setup.exe. Note that Inno Setup is the open source software we have used to produce the installer. Run the installer and you will see the following screen:

Click "Next". Note, that at this point the installer will check whether the installed fantom driver is up-to-date. The installer will report an error if that is not the case and you can chose whether the open the Fantom driver download page or to continue without installing or updating the Fantom driver. In the latter case, USB communication with the NXT might not work properly. If the installation continues, you will see the next page of the installer:

This page asks you to select the root folder of a 32 Bit Java Development Kit (JDK). You cannot continue the installation process without doing so. If none is installed, click the Download JDK button, download and installa a 32 Bit JDK and restart the installer. The selected folder will be assigned to the LEJOS_NXT_JAVA_HOME environment variable automatically at the end of the installation process.

The next step is to select the destination directory, in which leJOS will be installed:

You can change the destination if you need to. Click on the "Browse" button to change the destination. On the next page, you can chose which components to install:

It is usually not necessary to modify these. However, you may chose to omit the documentation (it is also available online) or you may chose to install any of the additional sources. The Sample and Example Projects are also contained in the samples.zip that is part of the leJOS Development Kit. The Sources of the leJOS Development Kit can be used to modify and rebuild leJOS it self. It is usually not needed, if you only plan on developing programs based on leJOS and do not plan to modify components of leJOS itself. All additional sources are also available as a seperate download. If any additional sources have been selected, the destination directories for them can be changed on the next page.

Note, that this page is skipped if no additional sources have been selected. The next page allows to adjust the folder in the start menu, that the leJOS shortcuts will be installed to:

The next page shows a summary of your choices:

The installation will start, if you click "Install". Note, that at this point the installer checks for any previous installs of leJOS. If any are found, their uninstaller is started. You cannot proceed with the installation without uninstalling the previous version.

After the installation complete, the following page will appear:

Uncheck "Launch NXJ Flash utility" if you don't want to start the graphical version of nxjflash, which allows you to upload the leJOS firmware onto the NXT brick. The leJOS firmware is needed to run any Java programs on the NXT. So it is recommened to run nxjflash. Note, that it is possible to revert to the original Lego firmware later.

If you chose to NXJ Flash, you will see:

Click "Start Program" and you will be asked:

Click OK and you will be asked:

If you select "Yes" all current files on the NXT are erased. It is a good idea to select this as old .nxj files may not work with the new firmware.

You will then see:

Make sure that your NXT is connected to the PC by the USB cable and witched on. Then press "OK" and you should see some progess messages, such as:

When your NXT has been updated, you will be asked:

If you have more NXTs to update, click "Yes". When you have finished click "No" and the flash utility will terminate and then the installer will terminate, and you are done.

Skip to the section below on testing your installation.

Back to top

Manual installation

If you have been using the GUI installer, skip this section and go to "Testing the Installation". This section described the manual install without the GUI installer.

Downloading and Unzipping

Download the file called leJOS_NXJ_0.9.1beta_win32.zip and unzip it to a location of your choice, e.g. C:\leJOS_NXJ.

Setting up environment variables

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 java and javac can be called from a command prompt or (2) set the LEJOS_NXT_JAVA_HOME environment variable to the directory of an installed JDK. Note that you can use JAVA_HOME instead of LEJOS_NXT_JAVA_HOME, however setting JAVA_HOME might intefere with other applications.

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:

Variable Value Examples
NXJ_HOME The folder you installed leJOS NXJ into C:\leJOS_NXJ
LEJOS_NXT_JAVA_HOME The folder where you installed the 32 Bit JDK C:\Program Files\Java\jdk1.7.0_02
C:\Program Files (x86)\Java\jdk1.7.0_02
PATH Prepend the bin of the leJOS Development Kit C:\leJOS_NXJ\bin;%PATH%

The Windows installer will automatically sets all three environment variables for you. Setting them manually is only required during manual installation. You can set these environment variables manually by going to Control Panel > System > Advanced > Environment Variables and creating them or editing existing values. You can set them either as user or system variables depending on whether you want leJOS NXJ to be available to all users or just the current user.

Using a Command Window

You will need to run command-line commands to test your installation and optionally to flash the firmware. If you plan to use IDE such as Eclipse or Netbeans, once you have installed your IDE, you should not need to use the command window any more.

You can start a command window on Windows XP by Start > Run and typing cmd. On Vista or Windows 7, type "Command Prompt".

Type set to list environment variables and check they are all set up correctly.

Flashing the Firmware

As 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. However, it is possible to revert to the original Lego firmware either by using the Software provided by Lego or by using nxjflash.

The 0.9.0 release increases the amount of flash memory used by the firmware and the startup menu, so the first time you flash this version of the firmware, existing leJOS NXJ files will be deleted.

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 (as described above) and either type the command nxjflash or nxjflashg followed by hitting the Enter key. The latter starts the GUI version of nxjflash.

If you chose nxjflash to flash the leJOS NXJ firmware, you will see some messages on your command window. If the NXT brick is already in firmware update mode (it makes a ticking noise), then the firmware will be uploaded immediately. Otherwise, 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. After the flashing procedure has finished, you should see the leJOS logo on your NXT and hear the leJOS startup sound. If your NXT has other firmware on it, or if nxjflash fails, you must manually put your NXT into firmware update mode. Press the reset button (at the back of the NXT, hidden in the hole near the USB port) 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.

If you chose nxjflashg, the GUI version of nxjflash will start. Instead of typing the command on the command line, you can also double click nxjflashg.bat in the bin folder of the leJOS Development Kit. When the program window opens, click on Start Program and follow the instructions. A more complete explanation is in the PC GUI Tools tutorial page.

Back to top

Testing your Installation

You can test your installation by following the steps for writing your first leJOS Program which are the next part of this tutorial.

Back to top