Getting Started on OSX


Getting Started on OSX

This version of the tutorial is for the 0.85 release of leJOS NXJ and is compatible with OSX10.4 or higher and both intel and ppc processors.

Prerequisites

Standard Lego Software

To run leJOS NXJ on OSX you will need the standard Lego software installed so that you can connect to your NXT using USB.

Intel macs require the 10.5 firmware (fix) update. This is true for OSX10.4 intel users as well. We have had several users report that this works... (the 10.5 update installer actually checks if your OS is 10.3+). PPC users need the 1.02 driver.

Java Development Kit

You will also need a Java Development Kit (JDK). 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://java.sun.com/. Follow the instructions for installing it. The 32 bit version of Java is required and at this time only version 1.5 is 32 bit.

Back to top

Downloading and Untarring LEJOS Software

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

Un-tar the release (you do not need to run the build script)

Back to top

(Optional) Bluetooth Stack

If you want to communicate with the NXT over Bluetooth, you will need a Bluetooth dongle or built-in support on your Mac, and a Bluetooth software stack. LEJOS is distributed with a 3rd party stack that is configured by default -- bluecove.

Back to top

Setting up the Environment

Environmental Variables

You need to set the following:

Variable Value Example
NXJ_HOME The folder you installed leJOS NXJ into /Users/me/lejos_nxj
JAVA_HOME The folder where you installed the JDK /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home
PATH Add the bin folders for the JDK and leJOS $JAVA_HOME/bin;$NXJ_HOME/bin;
DYLD_LIBRARY_PATH (Only necessary for using the Eclipse plugin) Add the bin folders for Fantom driver $NXJ_HOME/bin;

You can set these environment variables either as user or system variables depending on whether you want leJOS NXJ to be available to just the current user or to all users.

Set Up for Current User

Create or Edit ~/.profile and set your environment there.

If it does not exist, you can create it with TextEdit. If it exists, you can open it from a command prompt:


    $ open ~/.profile
    

Example:


     export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home
     export NXJ_HOME=/Users/me/lejos_nxj
     export DYLD_LIBRARY_PATH=$NXJ_HOME/bin
     export PATH=$PATH:$JAVA_HOME/bin:$NXJ_HOME/bin
      
Set Up for All Users

Same as for Current User set up except use:

/etc/profile

Example:


    # System-wide .profile for sh(1)

     if [ -x /usr/libexec/path_helper ]; then
        eval `/usr/libexec/path_helper -s`
     fi

     if [ "${BASH-no}" != "no" ]; then
        [ -r /etc/bashrc ] && . /etc/bashrc
     fi
     ## setloginpath added /usr/local/bin start at Fri Nov  2 18:44:47 EDT 2007
     ## Do not remove the previous line
     if [ `whoami` != "root" ]
     then
       export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home"
       export NXJ_HOME="/Applications/lejos_nxj"
       export DYLD_LIBRARY_PATH="$NXJ_HOME/bin"
       PATH="$PATH:$NXJ_HOME/bin:$JAVA_HOME/bin"
       export PATH
     fi
     ## Do not remove the next line
     ## setloginpath added /usr/local/bin end at Fri Nov  2 18:44:47 EDT 2007 
    

Back to top

Setting Permissions

Make the script files in the leJOS bin directory executable by cd'ing to that directory and executing the command.

chmod +x *

Back to top

Configuring USB

The fantom driver is now distributed with leJOS and configured as the default. There is no need any longer to do so in $NXJ_HOME/bin/nxj.properties

This means no additional driver download is necessary. The Standard Lego Software is the only prerequisite.

Back to top

(Optional) Testing with nxjbrowse

Test it by running nxjbrowse -u you should be able to see your NXT.

Back to top

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 a previous version of leJOS NXJ on your PC your existing files will be preserved, but if you have the standard LEGO firmware or other third-party firmware on your NXT, existing files will be lost.

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

You can either use the command line nxjflash command or the nxjflashg GUI program.

Using the command line:

Type nxjflash to flash the leJOS NXJ 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.

Using the GUI version:

The GUI version of nxjflash is NXJFlashG. You start it by running the file nxjflashg from the leJOS NXJ bin folder. When the program window opens, click on Start Program and follow the instructions. A more complete explanation is in the Windows tutorial "PC GUI Tools" section.

Back to top