These are my project notes from getting the 0.5.0-alpha release of leJOS working to develop Java programs for the EV3 in Eclipse on my Mac. After following these steps you will have a working Eclipse development environment that can send programs to the EV3 over wifi or Bluetooth. If you are using another release then refer to the leJOS forums for information.
NOTE: This note is for the lejos-ev3 0.5.0-alpha release only!
If you are using an earlier build of leJOS, or are from the future using a later build then always refer to the leJOS forum and the official wiki for leJOS EV3 release information. (PS: If you are from the future can I have next week’s winning lottery numbers please?)
Step 1: Download and install the leJOS sd card image.
First you need to download the current leJOS boot image from http://sourceforge.net/projects/lejos/files/lejos-EV3/ (you can also follow along the discussion in the leJOS forum: http://www.lejos.org/forum/viewtopic.php?f=18&t=5107). Install sd.img onto a 16 GB class 10 card. When it boots leJOS only sees a 1GB filesystem but you can expand the filesystems at a later point.
Step 2: Connect to the EV3 using Bluetooth
The EV3 supports Bluetooth PAN networking which creates a private point-to-point network between your Mac and the EV3. You can ssh to the brick, and also download programs directly from Eclipse onto the brick. This cuts out messy USB cables – a real bonus!
The IP address is 10.0.1.1. Use the Bluetooth menu on your Mac to connect to the EV3 and then open up a terminal window to test ssh firstname.lastname@example.org no password to log in.
Step 3: Configure your wifi
The default wifi configuration is stored in the /etc/wpa_supplicant.conf file. Modify it to read:
root@EV3:/etc# cat wpa_supplicant.conf
# Home wifi
psk=”THE PASSPHRASE FOR YOUR WIFI NETWORK”
Restart your EV3 and then when it restarts the EV3 connects onto your wifi!
Step 4: Test HelloWorld
To test if you have a working leJOS Java environment do:
and after about 15 seconds you will here some beeping and see “Hello!” appear on the EV3 screen. Success!
Step 5: Set up Eclipse for leJOS on the EV3
I created a new Eclipse workspace for EV3 leJOS code: EV3EclipseWorkspace. I did this to keep my EV3 development separate from the leJOS NXT development.
Step 6: Clone the lejos repository into Eclipse
Clone lejos-ev3 into a local directory: git clone git://git.code.sf.net/p/lejos/ev3
lejos-ev3. This takes a LONG time! It seemed to get stuck at 24% for what seemed like ages. Downloads about 400MB.
Step 7: Add a Git repo in Eclipse
Then go into Eclipse and enter the Git repository view:
Add a Git repository by clicking on the little “+” icon below:
And choose a local project and browse to the lejos-ev3 git repo that was cloned earlier:
Switch to the Java browsing view:
Choose File -> Import and select Git:
Then choose Local repository:
In the next dialog select the lejos-ev3 repository:
Click Next and it should import into the current project space.
Install jsch: You need jsch-0.1.50.jar from http://www.jcraft.com/jsch/. Download the jar file and install it in Eclipse by selecting Windows > Preference > Ant > Run Time > Ant Home Entries and clicking “Add External JARs…” to add the jsch jar.
Next connect to the EV3 using Bluetooth to enable Bluetooth PAN: 10.0.1.1. We need this to complete the copy step at the end of each build below.
Expand ev3classes and right-click on build.xml and edit the ev3.host to 10.0.1.1.
Select Run As… Ant Build to run the build and copy ev3classes.jar to /home/root/lejos/lib
Do the same for DBusJava as well, editing build.xml first.
Now let’s compile and run Hello World!
Edit HelloWorld build.xml to set the ev3.host property to 10.0.1.1 and then right-click to Run As Ant build. This copies HelloWorld.jar to /home/lejos/samples
Then go to the Samples menu on your EV3 and you’ll see HelloWorld.jar. Choose this and Execute program – after a minute or two it will run and display Hello! on the screen.
Step 8: Install Java 1.7
By default my Mac came with Java 1.6 installed, so I got errors on all of the projects in the lejos-EV3 repo. The solution is to download and install Java JDK 1.7 and then tell Eclipse to use the 1.7 JDK as the default environment. You can read more here:
So if you see this in your Project Explorer in Eclipse:
Then install Java 1.7 and tell Eclipse to use the new JDK: Goto Eclipse -> Preferences -> Installed JREs and click on Search, it finds the JDK 1.7:
Step 9: Build ev3sources and DBusJava
You need to compile the DBusJava project and then the ev3sources project before you can compile any of the EV3 projects. Right-click on the build.xml and choose Run As… Ant Build. You will need to connect to your EV3 using the Bluetooth PAN as before so the jar file can be uploaded to the EV3. Do the same with the ev3sources jar file.
Step 10: Create your first leJOS EV3 project!
Finally you can create a new project. Go File -> New -> Java Project and add a project name. Then right-click on the new project and do New -> Java Class. Give your java class a name and also select for a main function to be created. Then right-click on your project and go New -> File. Name this file build.xml. Finally copy the text from a build.xml file from an existing project in Eclipse. Edit the header of the build.xml file to be the name of your project, and to reference the main class name you just created:
<?xml version="1.0" encoding="ISO-8859-1"?>
Don’t forget to change the ev3.host property to the IP address of your EV3 if you are uploading over wifi.
Then right-click on your build.xml file and choose Run As… Ant build. The code will be compiled and uploaded to the EV3 in the /home/lejos/programs directory. If you navigate to the Files menu on the EV3 you will see it there.