How to install and configure LeJOS in your MAC

Artículo nº 3 de la serie de 21 artículos sobre LeJOS

logo LeJOS+MACWe have already seen LeJOS and Windows and also LeJOS and Linux, today, we are going to see how to install and configure LeJOS in our MAC. We will also see a brief introduction to the command line programming of LeJOS.

We are going to follow some very simple steps:

1. Install Java
2. Install LEGO USB Driver for MAC
3. Install and configure LeJOS
4. Connect NXT and LeJOS firmware download
5. Use LeJOS with command line

1. Install Java

In MAC Java comes pre-installed, so just make sure we have it latest version (at the time of writing this tutorial is 1.6), for this we go to apple and select “Software Update…”.

2. Install LEGO USB Driver for MAC

For our MAC to recognize NXT firmware restoration mode, you must install the patch from LEGO Mindstorms support webpage

Patch name: Mac Leopard Fix

Leopard Fix

3. Install and configure LeJOS

Go to the LeJOS Official Web and download the Mac/linux version.
Then extract the folder wherever you want, we have done it in Home

Now we have to configure envorinment variables for Java and LeJOS, so open Terminal and type

sudo pico .profile
This command will let us create the .profile file , or edit it if it is already created. Type your admin password and add the following lines into the file.

export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home
export NXJ_HOME=/Users/Phoenix/lejos_nxj
export DYLD_LIBRARY_PATH=$NXJ_HOME/bin
export PATH=$PATH:$JAVA_HOME/bin:$NXJ_HOME/bin

First line is the path where JAVA is installed.
Second line is the path where the lejos_nxj folfer was extracted.
Third one is only necesary if we are going to use Eclipse plugin (we will see it in another article)
And the last one adds the bin directory for LeJOS and JAVA

Modif profile

CTRL+X to exit (file name .profile) and Yes to save changes. Hit enter and you will be back to the Terminal..

We have to change now the permissions of the bin directory.
We have to access lejos_nxj/bin
cd lejos_nxj/bin (if you have it in Home directory)
and type
chmod +x*

For all this changes to have effect we have to reboot our computer.

IMPORTANT
If you have Snow Leopard installed in your computer and LeJOS is not working once you finich the installation process, just overwrite files inside lejos_nxj/bin for these ones bin_lejos_snow_leopard. It is a zip file, just unzip it and overwrite
¡Attention! You will have to change folder permissions again.
The files included in the zip file are patched files that force Java to execute in 32 bit mode, in order to be totally compatible with LeJOS.
This patch is not necessary for users with older versions of OS X.

4. Connect NXT and download LeJOS firmware

Once we have it installed and configured, let’s give it a try

First, let’s try to connect to our NXT, plug in USB cable and type

nxjbrowse -u

We should see something like this


NXJBrowser

Select NXT and hit Connect. When connection is established, just close nxjBrowser and type

nxjflashg

This command will let us download the new firmware in our NXT.


LeJOS Flash

Select “Start program” and Yes to delete NXT files.

5. Use LeJOS with command line

Let’s write our very first program, the Hello World, but let’s use the Terminal.

Open a text editor, we have chosen rText and write a file with the following content

import lejos.nxt.*;

public class HelloWorld {
public static void main (String[] args) {
System.out.println("Hello World");
Button.waitForPress();
}
}

In line 4, we have used the standard System.out.println method of Java, cause LeJOS can manage it perfectly, sending the output to the LCD display.

HelloWorld

Save as HelloWorld.java

- To compile it, type

nxjc HelloWorld.java

- To link it we have to use

njxlink -v HelloWorld -o HelloWorld.nxj

  • Modifier -v, is not mandatory, but will let us see linking process with verbose mode, really useful for debugging.
  • After -o we have to indicate the name of the binary file that will be created.

    - To download a previously linked file,

    nxjupload HelloWorld.nxj

    Modifiers for this command are:

  • -b /-u forces download with Bluetooth/USB
  • -d address
  • Luego -n name donde name

    - But, if when we have it compiled, we just want to link, download and run it with 1 command, the solution is

    nxj -r HelloWorld

    consola nxj

    We will see some LeJOS related info in the following entries:

  • NXT-MAC bluetooth connection
  • Installation and configuration of Eclipse for LeJOS on MAC

    Any doubt? just visit our forum.

    Otros artículos de la serie LeJOSLeJOS, la plataforma Java para LEGO MindstormsConectar NXT por Bluetooth a MACManejo básico del LCD y los botones en LeJOS

    Artículos relacionados:

    1. NXT voice controlled using LeJOS and MAC OS X

  • Escribe un comentario

    You must be registrado para poder escribir un comentario.