Starting leJOS USB transfer sample on Windows XP (Part 1) Pro Preview

In this episode I would like to show you how to enable the communication between the computer and the NXT brick, through the USB and using the leJOS project. Starting leJOS on Windows is pretty easy. But starting the samples and achieving the communication is the actual problem.

  • #20
  • 03 May 2013
  • 15:01

Mentioned Video Lessons:

Problems solved:

  1. Configuring PATH environment variable after Java installation
  2. Hardware reset of the brick



In this episode I would like to show you how to start communicating

between the computer and the NXT brick,

through the usb and using the leJOS project.


Starting leJOS on Windows is pretty easy.

But starting the samples and achieving the communication

is the actual problem.



Again I am starting from a brand new Windows XP installation working on a virtual machine under Ubuntu.

This are the steps I will try to follow.

I will open a new notepad so that you could see what am I typing.

I will directly download leJOS, because it will notify me if I have java and the right usb driver. Then we will have to download java but the jdk version. Then we will also have to download the usb driver for windows, that’s called Fantom driver. This Fantom driver is provided by LEGO. Then we would have to download again ant, a tool called ‘ant’, and we would do some setuping of system variables. If of course it is needed after the installation. And as a last step we will frash the brick and start usb communication, between the brick and the computer.



Let me start by downloading leJOS. We start Google Chrome as a browser we search for leJOS on the Internet, we go to their site, then to downloads, for the nxt brick, we download from sourceforge, and currently we are using version 0.9.1.


Direct link, it is currently downloading. After download is completed we open the file, run it, and we start setting up. The first warning that we would see is that we do not have the Fantom driver for usb communication and the install wizard will direct us to the site where we could download it. So we press OK. We go to the site and we download Fantom Driver.


For a PC. Download is completed. We open the downloaded archive and we start the setup file. Run. This will download the fantom driver from LEGO that is used for communicating through the usb with the nxt brick. Next... Next..


Ok. Download and installation is completed. Let me minimize this. And we start again with the setup wizard of Lejos. Now the next warning is that we do not have java development kit installed. It is important that we have java development kit installed not java runtime environment.  So we press ok and there is a very useful button here in the wizard.


I am currently working on windows xp and it is a 32 bits version so I download java platform and of course accept licence agreements and I download this version here for windows. After the download is completed, we open the file. Run and we install the java jdk version.


Next.. Next. It is pretty easy. We follow the wizard with all its steps and after the installation is completed we are ready.



Now after the installation of java one of the most annoying things that I have never understood in my career is that after the installation Java is not properly configured to run on this machine. You can go to start-run,open a command prompt and type “java” and you can see this very annoying message “java is not recognized as an internal or external command”. So we must do some things on our own.  This are configuring system environment variables, and we must do it in the following way. We open My Computer, Windows Explorer, we open folders, right click on My Computer, Properties that go to advanced Environment Variables. Now we must create a new special EV that is called JDK_HOME. So we press New - it is called JDK_HOME and it must point to the path where our java is installed. And our java is installed in Local Disk->Program Files->Java->jdk.


We copy this path. Right click copy, and we past it here. This is the path for our jdk installation. The next step is to add this EV to another EV that is called Path. This one here. So we edit our “Path” and at the end of the “Path” we add %JDK_HOME%\bin. In this way all the executables of java will be found in the command prompt. OK. OK.OK Close this CP. We open another one and we type java. And we can see that java is now found. We can even check the version of java that is currently installed. It is java 1.7



After java is installed we can continue with the installation of leJOS. We type “exit” here. We open the setup. Now we choose where our java is installed. It is installed in the jdk folder. Next we follow the wizard with all the steps. Now one important thing is that we would like to have the Sample projects installed and the source code of leJOS development kit. Next.Next.Next.Next. Installed. OK. Installation is completed, and we finish. After we finish we launch the Flash leJOS firmware. There is no brick currently connected on my machine. I will try to flash. There is nothing connected. So no NXT is found.


I will now connect our nxt to our computer, OK. I will make sure the virtual machine can see this device. There is a new firmware found. Device Ok. Lets try to flash this brick. OK. Yes.


You can hear this ticking of the brick. And now this problem happens very often. Sometimes it happens sometimes it doesn`t. When you try to flash the brick it enters into a state where it ticks like you hear it, but you can not install the new firmware. We can try to flash it. Ok. Yes. But there is no NXT found and what we should do now is to reset the brick using the hardware reset button. I will show you this just in a minute.



Now you can see that it is more than annoying this ticking. And the brick is not responding. It is connected to the computer from the usb but it is not responding and it is ticking. What you should do now is to try to reset the brick but using the reset button. The reset button is located right here in this hole. You can use a sharp tool just to get there and you press it and you hold for a 5-6 second maybe. You reset the brick.


And now we can try to flash the brick again. Lets try it. Flash. Ok. Yes.



After flashing the brick you can see the new firmware installed. You see it looks in a different way I will turn it off and then turn it on. And it says lejos 0.9.1.



After we have updated the firmware on our brick with the firmware provided by lejos, we see this window. I will close most of the windows, so that we could be more focused.


What have we achieved? We have downloaded lejos. We installed the java JDK version. We installed a USB driver. We configured the system variables. We have flashed the brick. And the next steps is to start communicating with this brick through the usb.


For this we should go to the samples of lejos. We open Windows Explorer. And now we are in Local Disk->Program Files->Lejos and we have the samples. This here is an archive with all the samples. We extract it here. Next. Next.


And in this samples we have two types of samples -> samples that could be run on the nxt brick, and samples that are run on the pc. Lets check the samples for the nxt brick. In src folder we have org/legos/sample/ and this are all the samples programs, they are all written in the java programming language and we can see a folder called usbreceive. This is the program for receiving usb information through the usb on the brick. If we were open this file, we can open it with Notepad, we can see the code of this file, and we can see it is written in java and it reads a new int from the usb, it converts it, it changes the sign of this integer, and then writes this integer back to the computer.


Lest check the program for, the program running on the pc. Again we have it in the samples, but this time in pc samples, source, org/legos/pcsample and we have again usbsend. This is the program for sending usb information from the computer to the Brick. UsbSend we can open it. We can see the code. It’s again written in java and I will not go into details on how this program works, but I would like to show you how to run this program on your computer. How to run the pcsample and how to run the sample for usb receiving on the nxt brick.



But I think this video is getting a little bit too long so I will leave the communication for part two of this video.