The leJOS Tutorial
Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail

Trail: Getting Started
Lesson: Your First Brick of leJOS

Your First Brick of leJOS (for Microsoft Windows)

The following instructions, which refer to the Microsoft Windows platforms (95/98/ME,NT,2000,XP), will help you to run your first leJOS program.
We presume that you are familiar with the Java language on an elementary level at least. If this is not the case, we encourage you to consult the first trails of the The Java Tutorial provided by Sun Microsystems.

Besides the LEGO MINDSTORMS RCX, the associated IR Tower and the leJOS environment (see below), you will need:

That's all you need except for the leJOS environment.

Download of the leJOS environment

You can find the actual version of the leJOS environment from the Download section of http://www.lejos.org.

Installation of the leJOS environment

  1. After you have downloaded the leJOS environment zip file, unzip it to an arbitrary directory - if you haven't a zip utility, you might try for example 7-Zip, which is available for free.
  2. Add the SDK's bin directory to your PATH environment variable.
  3. Set the LEJOS_HOME environment variable to the directory you installed lejos into:
    set LEJOS_HOME=< your lejos directory >
  4. Add leJOS's bin directory to your PATH environment variable:
    set PATH=%PATH%;%LEJOS_HOME%\bin
  5. Add the leJOS classes to your CLASSPATH environment variable:
    set CLASSPATH=%CLASSPATH%;.;%LEJOS_HOME%/lib/classes.jar;%LEJOS_HOME%/lib/pcrcxcomm.jar
  6. Set the RCXTTY environment variable to your 'tower' device:
    set RCXTTY=COM1 or set RCXTTY=usb.

leJOS-enable your RCX

To enable your RCX for the execution of leJOS programs, you will have to replace the original LEGO® with the leJOS operating system. This is easily done:
  1. Place the IR sensor of the RCX in front of the IR Tower
  2. Turn on the RCX
  3. Open a command shell and change to the bin directory of your leJOS installation
  4. call firmdl.bat
  5. the progress of the download is displayed in the command shell and on the display of the RCX; the RCX will double beep when the download is complete and display the battery voltage

If the download doesn't work, make sure that

The tower should blink green, when you start firmdl.

The original LEGO® firmware isn't deleted from the RCX, but stored away. Hence you may re-activate it by just removing the batteries for some minutes and replacing it.
The leJOS firmware will be lost in this case, though, and will have to be downloaded again to be useable on the RCX.
Note that you have to install the leJOS firmware only once (unless removing the batteries); nevertheless it may be downloaded as often as you wish, but the leJOS programs you have installed will be lost in this case.

Create and Run your first leJOS program

There's a simple "Hello World" style example program available in the checkDistribution folder of the leJOS distribution:

import josx.platform.rcx.*;

public class DistributionSmokeTest
{
public static void main (String[] args) throws Exception
{
LCD.clear();
TextLCD.print ("SMOKE");
Thread.sleep(1000);
TextLCD.print ("TEST");
Thread.sleep(1000);
}
}

To run this program, you will:

  1. Open a command shell and change to the check directory of your leJOS installation
  2. Compile it using lejosjc.bat:
    lejosjc.bat DistributionSmokeTest.java
  3. Link and download it to the RCX using lejos:
    lejos.bat DistributionSmokeTest
  4. the progress of the download is displayed in the command shell and on the display of the RCX; the RCX will double beep when the download is complete and displays a standing man
  5. Press Run to start the program; The words "SMOKE" and afterwards "TEST" will be displayed on the RCX
If lejosjc or lejos isn't found, make sure your PATH variable is set accordingly.
If the leJOS classes arent found, check your CLASSPATH variable.

Congratulations! You have run your first leJOS program on your RCX.

Troubleshooting

One of the steps above did not work for you? A look into the Common problems section might help.

Yet, if it doesn't, feel free to post your question to the lejos discussion list.


The leJOS Tutorial
Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail