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:
- The Lego device access Kernel modules are loaded without having the Lego VM running.
- 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.
- 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.
- Installs the Oracle Java SE Embedded JVM, JNA and leJOS classes so you are ready to run Java programs on the EV3.
- Includes shutdown scripts to power off the device when Linux is shutdown.
So what do you need?
- A micro SD card 2Gb or more in size.
- 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.
- 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.
- A WiFi Network and details of the SSID and PSK etc. needed to connect to it.
- A download of the Oracle Java SE Embedded JVM (see below for the link to follow).
- A Telnet or ssh program to connect to the EV3.
- Optionally an NFS server to allow you to easily run programs developed on your PC.
- Download the leJOS creation tool
- Unpack them on your Linux system using tar xfj lejosimg.bz2. This will create a directory called lejosimage that contains the tools.
- Download the Oracle Java SE Embedded JVM from the Oracle download site.
- Copy the downloaded tar file into the lejosimage directory.
- 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:
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.