Now you can experiment with a very early port of leJOS to the EV3 courtesy of Andy Shaw, one of the core developers of the leJOS framework. If you prefer coding in Java and enjoy the rich class library support offered by leJOS then this post is for you! But be warned; it’s early days and a lot of the sensor support is still being developed.

Andy provided a series of instructions for getting started on leJOS. If you need support with these steps then please visit the leJOS forum for help.

leJOS/EV3 SD Card creation tools

These tools are designed to help you create a bootable SD card for the Lego EV3. This card can then be used to run Java/leJOS programs on the device. The SD card image is based on the standard Lego firmware but has been enhanced to provide the following:

  1. The Lego device access Kernel modules are loaded without having the Lego VM running.
  2. The WiFi stack is loaded to allow connection to the EV3 via a supported USB WiFi adaptor. This allows you to connect to the EV3 via Telnet, SSH and NFS and makes program development very simple.
  3. Driver modules for Atheros ATH9K and Realtex 8192cu based devices are included and will be loaded automatically based on the detected WiFi chipset. The EV3 has been tested using the NetGear WNA1100 and EDIMAX EW-7811Un adaptors, but others may work if they use the same chipsets.
  4. Installs the Oracle Java SE Embedded JVM, JNA and leJOS classes so you are ready to run Java programs on the EV3.
  5. Includes shutdown scripts to power off the device when Linux is shutdown.

So what do you need?

  1. A micro SD card 2Gb or more in size.
  2. A WiFi dongle that is supported by the EV3. At the moment the only devices used are the NetGear WNA1100 and EDIMAX EW-7811Un. But hopefully this list will be expanded.
  3. A PC running Linux (the tools were created/tested on Ubuntu 12.10) to create the SD card and to use for program development. Can be a Windows/Mac OS system with Linux running under VirtualBox or VMware.
  4. A WiFi Network and details of the SSID and PSK etc. needed to connect to it.
  5. A download of the Oracle Java SE Embedded JVM (see below for the link to follow).
  6. A Telnet or ssh program to connect to the EV3.
  7. Optionally an NFS server to allow you to easily run programs developed on your PC.

Getting started.

  1. Download the leJOS creation tool
  2. Unpack them on your Linux system using tar xfj lejosimg.bz2. This will create a directory called lejosimage that contains the tools.
  3. Download the Oracle Java SE Embedded JVM from the Oracle download site.
  4. Copy the downloaded tar file into the lejosimage directory.
  5. You now need to set things up to allow access to your WiFi network. To do this you need to edit the wpa_supplicant.conf file in the lejosimage directory to provide the details of your network. The sample file looks like this:
ctrl_interface=/var/run/wpa_supplicant 
# Pers 
network={         
  ssid="legolan"         
  key_mgmt=WPA-PSK         
  psk=8e9116c7665b56a95c03e3e23ec707f4cbe18fea82d620d9b85b2f79fe34cfee         
  pairwise=CCMP TKIP         
  group=CCMP TKIP         
  proto=RSN 
}

This example file  defines a network that has an SSID of “legolan” and uses WPA2 authentication. The WPA wifi authentication protocol uses a pre-shared key (the psk field in the wpa_supplicant.conf file) to define the key. Edit this example file and change the ssid to be the ssid of your local wifi.

You find more details of the various settings and configuration options here: http://linux.die.net/man/5/wpa_supplicaant.conf and http://linux.die.net/man/8/wpa_supplicant. You will  need to run the wpa_passphrase command after changing the wpa_supplicant.conf file to convert your wifi passphrase into a psk hex value: http://linux.die.net/man/8/wpa_passphrase.

Now we are ready to create the boot image. First off we need to format the card. basically we are creating two partitions one DOS, the second Linux. To format the card hook up an SD card reader and use the command: ./format_sdcard.sh This will prompt you for sudo access as required. Take care when specifying the device to format, you could end up formatting your hard disk!

Once you have a formatted card we can create the image. First remove and re-insert the card. On most Linux systems the system will automatically mount the two partitions (called LMS2012 and LMS2012_EXT), if they are not mounted automatically you will need to mount them before continuing. Make a note of the location that that card has been mounted (on Ubuntu this will be /media/<your username>/), then issue the command ./update_sdcard.sh <mount point> <JVM tar file> Where <mount point> is the location that the SD card is mounted and <JVM tar file> is name of the file you downloaded previously. On my system the command line would be: ./update_sdcard.sh /media/andy ejre-7u21-fcs-b11-linux-arm-sflt-headless-04_apr_2013.tar.gz The script will then go ahead and create the boot image.

Once complete eject the SD card using the eject option in the Linux file browser and remove it from the reader. Make sure the EV3 is powered off and then insert the card into the EV3 SD card slot. Press the enter button to boot the EV3. As the system boots it will turn on the Red LEDs when these turn off the EV3 will be ready to use. Shortly after the red light turns off the LCD screen will display the leJOS logo. Just below this you should see the IP address assigned to the EV3. If you do not see an IP address displayed then something has gone wrong with the WiFi setup, check that you have correctly configured the wpa_supplicant.conf and that you are using a supported WiFi device. If necessary re-run the update_sdcard.sh command to recreate the image.

Once the EV3 has booted you should be able to connect to the displayed IP address using either ssh or telnet. Login as root with no password. Once connected you can now check that it is possible to run leJOS based Java programs. cd to the the /lejos/samples directory and type: jrun EV3HelloWorld After a short while the program should play some sounds, light up the EV3 LEDs and display a message on the EV3 display.