Showing posts with label Ubuntu. Show all posts
Showing posts with label Ubuntu. Show all posts

Thursday, January 9, 2014

Setting up Wifi on an EV3 running LeJOS

What is the point of having an awesome robotics kit running Linux if you cannot access the shell? That is a question I found myself facing once I had installed LeJOS on the EV3. Although I could place programs (Java .jar files) on the sd card directly) and execute them on the EV3 this became quite tedious quite fast. Fortunately, of the few Wifi dongles supported by LeJOS is the Edimax EW-7811Un which sells for $10 at Amazon. This amazingly small wifi dongle is an excellent add-on for the EV3 and works on the Raspberry Pi as well.



Once again the internet is full off conflicting advice on how to get the EV3 running LeJOS to automatically detect the Wifi dongle (Note: The stock Lego EV3 firmware never did detect it). The advice that worked for me came from this source.

The common pitfalls to avoid are: do NOT edit /etc/network/interfaces (no matter how many tutorials tell you to), you only need to modify /etc/wpa_supplicant.conf. And you can generate the psk in hex form by running the wpa_passphrase command as follows:
    wpa_passphrase <SSID>
and simply enter the passphrase when prompted to get the psk in hex format.

In summary load the microSD card (with the LeJOS partitions for EV3) in to your computer, mount the non-boot partition and edit /etc/wpa_supplicant.conf to enter your wireless network credentials. Once done, unmount the microSD card and load it in to the EV3. Start it up (it should boot in to LeJOS) and the EV3 should connect automatically to your specified wireless network.

Note: Once wifi is set up you can ssh in to the EV3 using the IP Address displayed by LeJOS on the EV3's screen. The username is root and the password is blank/empty. To allow scripts to ssh in to the EV3 I placed my public key in the /home/root/.ssh/authorized_keys file (which I had to create) and then simply added an entry for EV3 in my computers ~/.ssh/config file. Now I can access my EV3 over wifi effortlessly.

Programming Lego Mindstorms EV3 using LeJOS on Ubuntu Linux

I have been coveting a Lego Mindstorms Robotic kit ever since I learned there was one to be had and learning that the latest version, the EV3 runs Linux was the last straw. I was still hesitant because though the EV3 ran Linux there was no support for programming it in Linux, that is, from a PC running Linux. Out of the box the EV3 can only be programmed using a Windows or Mac machine, and even then only in a GUI suite ("visual programming") geared towards children.

What I needed was the power of a fully-formed language where I could program the EV3 using my Linux desktop (it is what I call my 7 year old laptop that I run only as a box). Lego had chosen to place Linux on the EV3 to make it more hackable and their foresight paid dividends when the LeJOS project was able to fork the open-source Lego kernel allowing them to place a JVM (Java Virtual Machine) and give access to the complete functionality of the EV3 using Java classes. Since I am an Android Developer by day, this was perfect.

The really great thing about the EV3 is that it comes with a micro-SD slot on which you can place your own bootable partition which allows you to change the firmware of the device without actually having to mod it. Basically, write a suitable image to a micro-SD card and the EV3 will boot from it. Remove the sd card and the EV3 will return to booting from the Lego firmware.

The LeJOS project provides a complete tutorial on how to create a micro-sd card that will run LeJOS on the EV3:

Stay tuned for more information on how to use a (supported) Wifi dongle (USB), program the EV3 using IntelliJ and automate the deployment of custom programs using ssh, make and gradle.

Happy hacking on the EV3.