DOC

Lejos.Install.Instructions

By Nathan Andrews,2014-06-27 21:29
11 views 0
Lejos.Install.Instructions

Installing NXJ

    First things first! Make sure you have installed the Java Software Development Kit (SDK) from Sun Microsystems, preferably 1.5 or later.

    ; Make sure your system has JAVA_HOME set to the root

    directory of the JDK (see step 5 below). The Sun installer

    should do this automatically.

    ; Your PATH must contain the SDK's bin directory (see step

    6 below for setting PATH). Again, the Sun installer should

    do this automatically.

    Now let’s install leJOS NXJ. Choose the appropriate

    instructions for your system below.

    Note:

    The leJOS download contains the latest setup instructions. If you experience any difficult using the steps below, refer to the instructions as some procedures might have changed. Windows

    Make sure you have installed the LEGO Mindstorms NXT software. The Windows version of leJOS NXJ uses these files to upload code via USB.

    1. Your first step on the path to leJOS bliss is to download the latest version from www.lejos.org.

    2. Unzip the contents into a directory. e.g. c:\java\lejos_nxj 3. Now we need to set some environment variables. Select Start > Control Panel > System. Click the Advanced tab, then Environment Variables (Figure 2-1).

Figure 2-1 Viewing the environment variables

    4. Click New to create a new environment variable. It can either be in System variables (if multiple users will use leJOS) or User variables if your account is the only one using leJOS. Type NXJ_HOME as the variable name and add the leJOS directory (see Figure 2-2). Click OK.

Figure 2-2 Setting the leJOS home directory.

    5. While you are in the environment variables, check to make sure JAVA_HOME has been set up. If not, add this variable and type in the directory to your Java SDK.

    6. Finally, add the bin directory to your path so you can use the leJOS compiler tools from the command line. Add the following to the end of your path variable (see Figure 2-3).

    ;%NXJ_HOME%\bin

Figure 2-3 Setting the path to the leJOS binaries.

    7. Now download and install the USB drivers from the following website:

    http://libusb-win32.sourceforge.net/#downloads

    Download the executable file that has bin in the name. When

    you run this file it will install the proper files. That’s all! You can now skip down to Uploading Firmware. Linux

    1. Download and decompress the tar file from www.lejos.org. 2. Add the environment variable NXJ_HOME and set it to the directory you installed leJOS.

    . Add the leJOS bin directory to your PATH. Depending on 3

    the privilege settings, you might need to adjust the execution permissions in the bin folder.

    4. Your PATH must also contain the ant binary (ant 1.6 or above).

    5. You need libusb installed so the leJOS tools can access your USB port. This can be downloaded from:

    http://libusb.sourceforge.net

    6. Now you need to build the distribution. Switch to the build folder and run ant. Note that depending on the privilege settings you might need to adjust the execution permissions in the release folder.

    That’s all. You can now skip down to Uploading Firmware.

    Mac OS X

    Macintosh owners can download binary files compiled just for their system. These files are a universal build, meaning they will work on both Power PC and Intel based Mac OS X computers. The leJOS tools for compiling and uploading Java code run in a shell environment, such as tcsh. Before you can do that, you will need to set up some environment variables for the tcsh shell. 1. Download the Mac OS X distribution from www.lejos.org. 2. Extract this file into a new location, such as

    /Applications/lejos_nxj.

    3. If you use the administrator login, you will need to create

    (or edit) the file .tcshrc in your user home directory. Run

    textedit from your Applications folder.

    4. Type the following two lines into the window (using the directory where you extracted leJOS), then save:

    setenv NXJ_HOME /Applications/lejos_nxj

    setenv PATH ${PATH}:${LEJOS_HOME}/bin

    5. Select your administrator directory (/users/administrator), and type .tcshrc as the file name. Uncheck the box saying If no

    extension is provided, use '.txt'” before you save. Then you'll get a

    warning box suggesting these names are reserved for the system (see Figure 2-4). Click Use '.' and it will save.

    Note: If you prefer to use csh instead of tcsh, you should instead edit/create the file .cshrc with the same lines.

    6. Bring up a Terminal window and type tcsh. You'll now be in

    a tcsh shell.

7. Type setenv to make sure your PATH and LEJOS_HOME

    variables are set up correctly. That’s all! You are ready to test

    leJOS.

Figure 2-4 Saving the environment variables in Max OS X.

    Uploading the Firmware

    It is much easier and faster to upload firmware to the NXT than it was with the RCX brick.

    1. First we need to place the NXT brick in firmware upload mode. The reset button is cleverly hidden in a LEGO pin hole so you don’t accidentally press it. Turn on the NXT. Using a bent

    paperclip, insert it into the hole in the upper-right corner of the underside of the NXT brick (see Figure 2-5). Hold the button for at least four seconds to erase the current firmware and put it into firmware upload mode.

    Figure 2-5 Using a paperclip to activate firmware upload mode. 2. Your NXT brick should be making a soft pulsing sound. Now we need to upload the firmware. Plug in your USB cable and type:

    nxjflash

    3. After a very brief moment you will see the leJOS NXJ logo and a menu system will appear. Your NXT brick is now ready to accept Java code.

    Warning:

    There is a theoretical limit to the number of times you can replace the firmware on your NXT before it wears out. Every time you replace the firmware, a piece of data called a lock bit is used up. This bit is rated to work 100 times (minimum) before it expires. However, don’t let this dissuade you from replacing the firmware with something you want more. Most engineers agree that the lock bit will last far in excess of 100 times. Chances are you will never even notice this limitation and you probably won’t replace your firmware enough to approach even 100.

Compiling and Uploading Java Code

    In this section you can try compiling and uploading some sample code from the command line. Windows users can enter the command line by selecting Start > Run and then typing cmd (Click OK).

    1. From a command line prompt, change to the samples\tune directory where you installed leJOS.

    cd \java\lejos_nxj\samples\tune

    2. You can optionally open the file Tune.java with a text editor to view some leJOS code. Compile the sample Java file:

    nxjc Tune.java

    4. This creates a file called Tune.nxj. Now it is time to upload this file. Plug in your USB cable (if you own a Bluetooth dongle you don’t have to plug this in). Turn on the NXT by pressing the

    orange button and type:

    nxj r Tune

    After a moment you should hear a tune play from your NXT brick. The r argument runs the program automatically. If you leave out this argument, it will appear in the menu system, where you can run it manually.

    Installing a Development Environment

    As we have seen, Java programming is possible with a text editor and a command line. However, it’s easier to click on buttons to make things happen rather than typing commands and optional parameters. Also, most text editors don’t have many features to

    help you enter code. It won’t tell you when you’ve misspelled the name of a class or forgotten a bracket.

    An IDE, or Integrated Development Environment, is a tool that allows you to enter, compile, and upload code to your NXT using simple buttons. It also monitors code syntax, coloring your code so you can more easily identify the parts. This section will suggest a free, open source IDE for your leJOS NXJ needs.

    One of the best open source IDEs is Eclipse by IBM (see Figure 2-6). It’s free, powerful, and easy to use. It makes sense to use a

    more advanced IDE with the NXT since your code can grow quite large.

Figure 2-6 Programming in Eclipse.

    Setting Up Eclipse

    1. Download Eclipse from: www.eclipse.org

    2. Decompress the files into a directory. This will be the

    permanent location for Eclipse.

    3. That’s it. Eclipse uses no setup and doesn’t store registry

    settings or copy native library classes to other directories.

    To run Eclipse, double click the executable file in the

    Eclipse directory (or create a shortcut to this). To uninstall

    Eclipse, merely delete the Eclipse directory from your

    computer.

    When you first run Eclipse you can browse some optional help files and tutorials. If you want to get right to Eclipse programming, close the Welcome tab.

Using Eclipse with leJOS NXJ

    Now that you have Eclipse installed it’s time to configure it for leJOS NXJ.

    1. Set up a project in Eclipse for your leJOS NXJ code. Click

    on File > New > Project and you will see the new project

    Wizard (see Figure 2-7). Select Java Project and click next.

Figure 2-7 Creating a new project in Eclipse.

    2. For project name enter something like leJOS NXJ. Click

    Next and then Finished. Eclipse creates a new folder for

    your leJOS NXJ code.

    3. Now we need to set the Eclipse classpath to the leJOS

    classes. In the Eclipse menus select Project > Properties

    and you will see a Properties window for your project.

    Select the Libraries tab and select Java Build Path in the

    left hand frame (see Figure 2-8).

Figure 2-8 Changing project properties.

    4. Click on Add External JARs… and browse to the

    classes.jar file in the lib directory where you installed

    leJOS. Click OK.

    5. Now we need to set up the leJOS tools to compile and

    upload code to your NXT brick. Select Run > External

    Tools > External Tools… to bring up a new window. Select

    the Program item and click the New button (see Figure 2-9).

Figure 2-9 Adding leJOS tools to Eclipse.

Report this document

For any questions or suggestions please email
cust-service@docsford.com