Download presentation
Presentation is loading. Please wait.
1
Java on the LEGO Mindstorms EV3
Lecture 3 Java on the LEGO Mindstorms EV3
2
Objectives Install JDK 7 on your computer.
Install leJOS on your computer and your EV3 brick. Intall leJOS Eclipse plugin. Set Eclipse preferences. Connect your EV3 to your computer. Download and run our first EV3 Java program.
3
Limitations of EV3 Software
A big limitation of the EV3 programming is the difficulty in storing variables. As an example suppose we have the following situation: The Ultrasonic sensor has measured the distance to an obstruction (d). The robot has wheels with a known radius (r). How can we determine the number of wheel rotations to get within 2 cm of the obstruction? This is an easy math problem but it would be difficult (not impossible) to do this with the provided EV3 software. Any situation where we want to store and process data would be more easily handled using more traditional programming languages like C, Python or Java.
4
Hacking the Brick To install a new programming language on our EV3 it is necessary to install a new operating system. The EV3 actually already runs a version of Linux, but it is set up to hid the details and only present the “friendly” EV3 interface. We need to install a new version of Linux, one with a Java Virtual Machine. There are a couple of different packages we could use: EV3dev – this installs general Linux where you can add the language of your choice, Python, C, Java, etc. leJOS – this is a Java specific install
5
Installing leJOS on EV3 Installing leJOS basically consists of:
Downloading some files Installing them in a very specific way on a micro SD card Adding a file to specify the IP number for the brick. Putting the SD card in the brick and restarting it. None of this is particularly hard but it is tedious. I will provide you with an appropriate SD card with leJOS already installed. Instructions on how to do this are available on the Wikispaces site.
6
Installing JDK 7 So that you can write and compile Java software for the EV3 using Eclipse, it is necessary to also install leJOS on your computer. First off you computer probably has Java 8 installed, but leJOS uses Java 7 so you will need to install the Java 7 development kit (JDK 7). Go to and download the version of JDK 7 for your computer. Run the installer to put it on your system. You can have two different JDK packages at the same time so this should not replace JDK 8.
7
Installing leJOS on Your Computer
Next you need to and download the source file leJOS_EV3_0.9.0-beta.tar.gz. Unpack this file in an appropriate directory. Inside the result you will find the file lejosimage.zip – decompress this file. That is it, leJOS is installed, but you still need to tell Eclipse how to use it.
8
Installing leJOS Plugin in Eclipse
Next you need to install the leJOS plugin in Eclipse. Start Eclipse and select Help > Install New Software… Click the Add... Button.
9
Installing leJOS Plugin in Eclipse
In the resulting dialog box type an appropriate name (like “leJOS EV3”) and the URL . Click OK.
10
Installing leJOS Plugin in Eclipse
Now you should see leJOS EV3 Support as an option – select it and click Finish.
11
Set Eclipse Preferences
Next you need to select Preferences in Eclipse and select leJOS. Enter the directory that resulted when you unpacked the downloaded leJOS file as EV3_HOME. Click the check box beside Connect to named brick and enter as the name. Click Apply.
12
Set Eclipse Preferences
While still in preferences, select Compiler. Set the Compiler compliance level to 1.7. Then click Apply and OK.
13
Connecting the Brick The brick needs to be connected to your computer.
You can connect using a USB cable or using Bluetooth. If you want to use the include USB cable then plug the small end into the EV3 brick and the large end into a USB port on your computer. Bluetooth can be a little flaky so I would recommend the USB connection.
14
Renaming the Brick If you want to connect using Bluetooth, you will need to name your brick and then pair it with your computer. You need to pick a unique name for each brick so you can tell them apart. To name your brick you need to go to the System menu on the brick.
15
Renaming the Brick In the System menu go to Change Name.
When you do this you will see the following on the screen.
16
Renaming the Brick You can select letters one by one.
“U” on the bottom row gives you upper case letters. “l” gives you lower case letters. “x” deletes at letter. “D” signals you are done. In this example I changed the name of my brick to “Henry”. You will need to restart the brick after you complete the name change.
17
Pairing with Your Computer
Once the brick restarts go to the Bluetooth menu.
18
Pairing with Your Computer
Within the Bluetooth menu select Search/Pair.
19
Pairing with Your Computer
On you computer do what you need to do to pair with a Bluetooth device. This is an example on a Mac.
20
leJOS HelloWorld If you are lucky everything should now work.
Let’s try a simple program. Create a new project called EV3HelloWorld but this time create a LeJOS EV3 Project. Make sure the execution environment JRE is JavaSE-1.7.
21
leJOS HelloWorld Just as before add a HelloWorld class.
You could run our previous HelloWorld.java program, but the text will disappear very quickly. We can add line to our code so that the EV3 will wait for a button press before exiting the program. Here is the new HelloWorld program.
22
leJOS HelloWorld This time we import a library that will give us access to methods to manipulate the EV3 hardware. import lejos.hardware.*; At the end of the program we add a call to a method to wait for a button press. Button.waitForAnyPress();
23
Running HelloWorld When you run your program the first time you must select what kind of application it is. This time it is a LeJOS EV3 Program.
24
Running HelloWorld In the console window you should see the following in the console pane.
25
Running HelloWorld On the EV3 you should see this.
26
Running HelloWorld Followed by this.
The program will exit when you press a button.
27
What Could Go Wrong If the EV3 is not correctly connected to the computer, the console window will hang trying to download the program and will eventually time out. Check your settings: IP number BlueTooth – if you can’t get BlueTooth to work go to the USB cable. USB cable
28
What Could Go Wrong If your Java compiler is using JDK 8 the program will download correctly, but will crash the EV3. In this case you may need to go back to Eclipse preferences and select Compiler. This time you should click on Configure Project Specific Settings… You will need to select the settings for your leJOS project.
29
What Could Go Wrong Set the Compiler compliance level to 1.7.
Try to run your program again.
30
Homework Get HelloWorld working on your EV3 brick.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.