Sjefdesign

Online Industrial Design Portfolio

How to install Java on leJOS NXT for Mac OS

By Sjef Fransen • Oct 6th, 2009 • Category: Assignments

Contents of the Tutorial

  1. Install Java
  2. Instal Lego USB Driver on MAC
  3. Instal and configure Lejos
  4. Instal and configure Eclipse
  5. Create the hello World with Eclplse and load it into the NXT.

1. Install Java:

The benefit of mac OS x is that java runtime development will be automatically installed on your operating system. To make sure you have the latest version of Java on your Mac you can use the Software Update. ...1»

2. Install Lego USB Driver

Go to this website and download the mac OS 10.5 (Leopard) firmware Fix for mac. (479 Kb) ...2»

Install the package by clicking opening the disk. and follow the instructions on the installer. You can leave all settings to default.
...3-12»

3. Instal Lejos

Go to the website and select the second download link for Linux/Mac OSX leJOS NXJ. Select the newest version link. ...13»

Extract the file lejos_NXJ_0_x_x.tar and place the folder lejos_nxj in your home folder of the mac system. ...14»

Now it is time to set the environmental variables for Java and Lejos. To do this we need to create or edit the .profile file. This can be done in the following way.

Open Terminal (/Applications/Utilities/Terminal) and write “sudo pico .profile.” ...15»

Save the file by ctrl – x and select yes to save the data. Hit return to exit the pico mode and come back to the terminal.

There is a difference between Leopard and Snow Leopard. In order to run Lejos on Snow Leopard one should replace the bin folder with the following files.

Now we have to set the permissions

Make a script file in the leJOS directory executable by typing in terminal ”

cd lejos_nxj

cd bin

After that execute the command:

chmod +x *

and hit return. ...17»

After you have rebooted your system you can test the connection of your NXT with the computer by plugging it in and type in terminal (/Application/Utilities/Terminal) “nxjbrowse -u”. ...18»

After you have successfully established a connection with your NXT you can flash it with LejOS. Type in the terminal “nxjflashg” and hit return. Select ‘Start Program’ and select yes to overwrite and delete the existing software. ...19-22»

Now the LejOS software is installed on your NXT and you can use it to program Java files on it with for example Eclipse.

4. Installing Eclipse.

Go to the website and download Eclipse IDE for Java EE Developers (188 MB). ...23»  Eclipse is a Java program and does not needed to be installed on the computer, instead export the .tar file to your computer somewhere where you can find it. ...24-25»

Start the program by clicking on the Eclipse icon.

You will be welcomed by a welcome screen and first choose a location where you want your workspace to be located. You can use the default setting. ...26» You will see the normal background of eclipse. ...27»

Now you have to create a new project. File->New…->Project. ...28» Select a Java Project in the Java directory. ...29» Then you can create a project with a project name for example lejos_nxt. (you better use no spacing) And select the execution environment to J2SE-1.3, because this has the best compatibility with the leJOS NXT. ...30»

Open the preferences of the project you have just created by selecting the directory and than File–>properties (Alt + return) ...31» and click the Java Build Path tap on the left. ...32» Add an External JARs by clicking on the button ‘Add External JARs’. Select in the directory lejos_nxj/lib the file classes.jar. ...33»

Select the Java Compiler on the left tap and change the compiler compliance level to 1.3 because that fits better to the environment of the NXT. Apply the new settings and select ok. ...34»

Now we have set the compiler and the library files it is time to make a connection to the NXT within Eclipse. Select RUN->§External Tools-> External tools configuration… ...35» and create a new launch configuration by clicking on the ‘New’ button. ...36»

Name the new configuration: lejos_Download and fill in for the location:

/Users/xxxxx/lejos_nxj/bin/nxj

The xxxx should be replaced with your home directory of the computer.

For the working Directory and arguments fill in:

Users/XXXXXX/lejos_nxj/bin

${java_type_name}

...37» Click on apply and after that close the window.

Now we can create a shortcut to this new configuration by clicking on the run_lejos icon and select: organize favorites… ...38» Then click on add and select the lejos_download. ...39» Confirm it by clicking on OK and after that again on OK.

5. Create a Hello World for the NXT and load it into it.

Select the directory lejos_NXT and then add a new Class by clicking File->New-> Class. ...40»

Fill in the Source folder lejos_NXT/src and the name Helloworld. Also mark the public static void main(String[] args) option and leave the rest as it is. Click on Finish. ...41»

Open the HelloWorld.java by double clicking on it and copy the following code to the first line:

import lejos.nxt.*;

Place within the main function the following code:

LCD.drawString(”Hello World!”, 2, 2);

LCD.refresh();

while(true);

...42»

Save the file by File->Save (cmd + s) and connect the NXT to the computer via the USB cable. Make sure the NXT is switched on and has leJOS running. Now hit the lejos_download button and the file should be uploading and will give a message when finished.

...43»

Now it is your time to play with the robot and the NXT. Enjoy!

Pic1

Pic2
Pic3Pic4Pic5Pic6Pic7Pic8Pic9Pic10Pic11Pic12
Pic13
Pic14

Pic15

Enter your administrator password and then copy the following lines in the file.

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

And change the /Users/!!!!me!!!!/lejos_nxj according to your own home directory. [slider title="...16"]Pic16

Pic17
Pic18
Pic19Pic20Pic21Pic22
Pic23
Pic24Pic25
Pic26
Pic27
Pic28
Pic29
Pic30
Pic31
Pic32
Pic33
Pic34
Pic35
Pic36
Pic37
Pic38
Pic39
Pic40
Pic41
Pic42
Pic43

Leave a Reply