1 Create the leJOS bootable SD card

By default the EV3 bricks starts the Lego menu application. To get access to the Linux file system and execute Java byte code it is necessary to configure a special SD card and insert it into the SD card slot. If the card present, the EV3 boots the leJOS menu application instead of the Lego menu. If you remove the card, the brick starts again with the Lego menu. Proceed as follows to create the leJOS SD card:

 

  • Provide an empty Micro SD card with minimum 4 GB and maximum 32 GB. It is highly recommended to use the fast class 10 type.
microsd
  • Insert the card into a card reader
cardreader

 

  • Download the card image from here (ev3sdcard.zip, approx 400 MB) and unpack it in any directory using an unzipper that supports large zip archive (e.g. WinRAR). You get a single file with .img extension. Start an USB Image Utility to burn the image to the SD card. Recommandationunder Windows: USB Image Tool, under Mac/Linux: ddutility. Be very careful to select the SD card drive and not something else, otherwise you destroy your data.

 

  • Insert the SD card into the EV3 card slot and press the turn-on button

microsd
   

2 Connect to the EV3

All connections to the EV3 use the TCP/IP protocol, but the physical transport channel may be USB, Bluetooth or WLAN. When booted with leJOS, a Linux Secure Shell (SSH) server with Secure Copy (SCP) is started (but no SFTP server). The EV3 replies also to ping requests. Ping is the easiest way to check if the IP link to the EV3 is working. The default IP address is 10.0.1.1 as seen on the leJOS start screen.

For further investigations you should use a SSH console program. Under Linux and MacOS a SSH console is integrated in the OS, under Windows you may use PuTTY, a free SSH and telnet client. As file explorer the GUI-based WinSCP is recommended.

Next you learn how to connect your PC to the EV3 via USB, Bluetooth or WLAN.

 

2.1 Connect via USB

One practice to communicate with the EV3 is to connect a USB cable between its micro USB port and your PC. The EV3 does not act as an ordinary USB device, but like a IP access point using the Remote Network Interface Specification (RNDIS) that provides IP connectivity over USB. To use this protocol, a RNDIS driver must be present. Under MacOS the driver is part of the latest version of the operating system. Under Windows the driver has to be installed manually. For Windows 7 or 8 proceed as follows:

  • Connect the EV3 via USB to your PC. The automatic driver installation fails

  • Download rndis.zip (7 kB) and unpack it in any folder, e.g. d:\down. In a file explorer you see the two files RNDIS.cat and rndis.inf


  • Start the Windows Device Manager and unfold Other devices. Right click on RNDIS/Ethernet Gadget and select Update Driver Software
ev3ndis1
  • A window appears. Click Browse my computer for driver software and select the folder where you unpacked the driver files, e.g. d:\down. Click Next.

 

ev3ndis2

ev3ndis3

  • After a minute or two a window opens to confirm that the driver is successfully installed

For Windows 10 proceed as follows:

  • Connect the EV3 via USB to your PC. The automatic driver installation fails

  • Download rndis.zip (7 kB) and unpack it in any folder, e.g. d:\down. In a file explorer you see the two files RNDIS.cat and rndis.inf

  • Right click on rndis.inf and select Install

  • Open the device manager. Under Network adapters, a new device USB Ethernet/RNDIS Gadget appears. Right click and select Properties

  • Open the tag Advanced and enter for Network Address the Value 10.0.1.1

 


To check if the connection is established, open a console window (command prompt) and type ping 10.0.1.1<return>. If you get a reply from the EV3, your IP link to the EV3 is working

ev4ndis4.

Under MacOS and Linux, no driver installation for RNDIS is needed. Just connect the EV3 via USB and open a command shell. Type ping 10.0.1.1<return> to check the link.

 

2.2 Connect via Bluetooth

The Bluetooth Personal Area Network (PAN) protocol is used to establish an IP connection via Bluetooth. The EV3 acts as IP access point like a smartphone or PC based access point (Bluetooth tethering). This is the recommended connection method because you don't need a cable nor a WLAN adapter.

You can change the robots friendly Bluetooth name in the EV3 menu under System - Change name. To enter a new name, move the cursor block using the cursor keys. Confirm each letter by pressing Enter. To finish, move to ✓ . Then reboot the EV3.

Boot the EV3 with leJOS and make sure that Bluetooth is switched on in the leJOS menu. There is no other action needed on the EV3 to establish the IP connectivity over Bluetooth

On the remote PC/smartphone/tablet you must pair the EV3 like you do it with any other Bluetooth device. Proceed as usual and perform a Bluetooth search. When the EV3 is seen, add the new device. If a security code is shown, confirm it; if a key is required, enter 1234.

To enable IP over Bluetooth, the EV3 must act as PAN server. Proceed as follows:

PAN under Windows:

  • After the pairing is performed (and each time the EV3 is turned on), the EV3 must be made active as IP Access Point. In Devices and Printers right click the EV3 symbol and select "Connect using > Access point".
ev3ndis1
PAN with a Smartphone/Tablet (Android):

  • Perform a Bluetooth search and pair the EV3 while ignoring the passkey. If a key is required, enter 1234.







  • Enable Internet Access (or something similar) for the paired Bluetooth device (with Android only available since version 4.0+)

ev3ndis1

ev3android2

PAN under Linux (Ubuntu):

  • In the Bluetooth Setting you must enable the checkbox "Use your mobile phone as a network device (PAN/NAP)"
ev3_pan_linux

  • After the pairing is performed (and each time the EV3 is turned on), the EV3 must be made active as IP Access Point. In the Network Icon Menu click the EV3 Network. After a while a confirmation box is shown.
q
ev3_pan_linux
PAN under MacOS:

  • Click the Bluetooth icon and perform a Bluetooth device search. Pair the EV3 while ignoring the passkey (if a key is required, enter 1234). In the Bluetooth control panel the EV* will be shown as not connected.

  • Click the Bluetooth icon and move the cursor to the EV3 entry. Select the "Connect to network" option.

 

 

 

2.3 Connect via WLAN

To connect the EV3 via WLAN an external USB WLAN adapter must be inserted into the (standard) USB port. Currently only one adapter type is supported by the Linux system: Netgear WNA1100 WLAN stick (also called Netgear N150 Wireless Adapter). The adapter must be inserted before booting the EV3. Make sure that a Wireless router using the WPA (WPA-PSK) security protocol is available, its WLAN DHCP is turned on and you know the SSID.

Proceed as follows to connect the EV3 to the router for the first time:

  • Select in the leJOS menu Wifi and wait a moment. The SSIDs of all available access points (AP) are displayed

  • Select the AP you want to use

  • A screen with many characters is shown where you must enter the WPA security password. Select letter by letter using the cursor keys and type Enter after each selection. To finish, move to ✓ and press Enter. After a while (be patient!) the additional IP address provided by the router's DHCP is displayed, e.g. 192.168.1.101

  • To check the link, connect your PC to the same router (via Ethernet or WLAN), open a console and type ping <ipaddress><return>, where <ipaddress> is the address displayed on the EV3 screen, e.g. ping 192.168.1.101<return>

  • If you get a reply from the EV3, your IP link to the EV3 is working

  • The next time you boot the EV3, it connects automatically to the AP at startup.

 

2.4 Connect from the Internet (WAN)

Now your EV3 is connected to a WLAN router and the router is connected to the Internet, you can make it visible from outside the local area network. Since the router firewall normally blocks requests from the WAN to the LAN, you must open the port by configuring the router accordingly. The setup depends on the router type, as an illustration we show the procedure for a LINKSYS router (by Cisco).

For SSH and SCP you must open IP port 22, the BrickGate server uses IP port 1299 as default. In the IP address field you enter the IP of the EV3 (that may vary because the EV3 is configured to use DHCP).

 

ev3router

If you want to connect a via a remote SSH or SCP client, you have to open IP port 22, to get access to the BrickGate server in standard configuration, you must open IP port 1299.

 

3 Exploring the Linux file system using Telnet, SSH and SCP

Once the IP link is established, you may log in the EV3 using a Telnet, SSH or SCP client. Under Linux and MacOS command line versions of all these clients are ready to use without any additional installation. Under most flavours of Windows a command line version of Telnet is also preinstalled. Keep in mind that Telnet uses IP port 23 and SSH/SCP port 22. So if you connect via WLAN, your WLAN router/firewall must be have these ports open.

To connect the first time to your EV3 open a terminal (command prompt) and type telnet 10.0.1.1<cr>. Log-in as user root and empty password. Under LInux and MacOS you may also connect with SSH by typing ssh 10.0.1.1 -l root<cr>. When the password is requested, enter <cr> for an empty password. Under Windows a GUI-based client is recommended. A sample session with SSH looks like this:

Install PuTTY (get the download link from an Internet search) and start it. Enter the IP address (via USB and Bluetooth: 10.0.1.1, via WLAN: address displayed in the EV3 menu).

ev3putty

A console window opens and you log in with username root and empty password. You are now in the home directory of the root user and you can perform Linux bash commands with root privileges, e.g.

ls list the files in the current directory
uname -a show the Linux version
ps list all running processes with their PID

ev3ssh

With ps you also see the Java VM running the leJOS menu:

ev3process

You can stop the menu and the VM by killing the process:

ev3killprocess

and all EV3 buttons are dead.

To explore the file system, it is convenient to use the GUI-based SCP client WinSCP. Select the SCP protocol in the File protocol field.

ev3winscp

Use an empty password:

ev3winscp1

and ignore the error message:

ev3winscp2

You may navigate to the /home/root/lejos/samples directory and see all programs there:

ev3winscp3

To convince you that the EV3 is full-fledged computer running Linux, write HelloEV3.java with your favorite Java IDE and create a JAR file HelloEV3.jar.

public class HelloEV3
{
  
public static void main(String[] args)
  
{
    
System.out.println("Hello EV3!");
  
}
}

Upload HelloEV3.jar to the EV3 with WinSCP and execute it in the SSH console using the jrun command (which has the same command line options as the java command).

ev3winscp3

You may also dive deeper into the Linux file system and have a look into the /bin directory where you find the jrun script file among other scripts that you may inspect.

 

4 Python programming with the EV3

The SD card image distributed from this site contains an Python 2.7 interpreter for embedded system that is automatically installed together with the leJOS installation. Some additional Linux scripts are added into /home/usr/sbin, so Python is ready to be used after the leJOS system boots. As usual Python scripts run fast and efficiently on this ARM processor. Even if you are not (yet) a Python programmer, open a SSH shell and enjoy, how easy programming may be.

ev3py1

The additional shell scripts in /usr/sbin are immediately available in a SSH command shell because this directory is in the system path. You may modify them or add your own scripts here. Make your own scripts executable by calling chmod +x <your_script>.

pyrun <script>

Starts Python and executes the given Python script with specified pathname
e.g. pyrun /home/python/scripts/HelloPython.py
(with no <script>: Invokes the Python interpreter)

pyexec <script> Starts Python and executes the given Python script in /home/python/scripts/
e.g. pyexec HelloPython (no .py extension needed)
killjava Kills all running Java (JRE) processes like the lejos Ev3Menu or any user Java program
runmenu Starts the leJOS menu that displays some useful debugging information
jrun <prog> java syntax same as in Java SE, e.g. java -jar MyProg.jar (no classpath for leJOS)
runprog <prog>

Stops all running Java processes and starts the JRE with given JAR in /home/lejos/program
e.g. runprog MotorEx1 (no .jar extension needed)

The classpath is extended to include the leJOS and EV3LibA packages. After the program terminates, the pending Java processes (e.g. the leJOS menu) is resumed.

Python scripts have access to the EV3 hardware via the BrickGate server. For more information consult the BrickGate site.

 

5 Using the Dynamic Update Client (DUC) of the BrickGate Server

The EV3 may serve as front end processor for data acquisition using its sensors (temperature, humidity, luminosity, etc.) or for switching relays connected to the Prototype (SuperPro) board by HiTechnic. It is also highly instructive to connect simple home brew electronic circuits to the EV3 to acquire data or control machines and devices. Remote control via the internet adds an extra thrill and challenge to these projects. As seen above, connecting the EV3 to a WLAN access point that includes an internet (WAN) connection is simple. The only catch is that the IP address of the router (and thus for the EV3) may be changed unpredictably by the internet provider (unless an expensive fixed IP is purchased). There is a workaround to this problem: The remote client does not connect directly to the router but via a special internet relocation server with a fixed host name that is aware of the router's current IP address. Such relocation services are provided (even for free) from different companies, one of them is www.no-ip.com.

This technique requires that the EV3 sends periodically the current IP address of the router to the relocation host. Such an application is called a Dynamic Update Client (DUC). Because most internet providers renew the DHCP address only once in day or even less frequently, a DUC update period of 1 to 5 minutes is adequate for most applications. But of course the connection from the remote to the EV3 may fail during this time interval.

The BrickGate server includes a DUC that conforms to the requirements of no-ip.com and may be manually configured by a properties file ev3jlib.properties that is in the /home/root directory of the EV3 file system. (The DUC is disabled by default.)

Follows the procedure how to get a free no-ip.com account and configure it:

  • Use the same router where the EV3 is attached. At http://www.no-ip.com click Sign Up

  • Fill in the form: e.g.

    ev3no-ip1
    Select one of the free domain names, e.g. zapto.org and click Free Sign Up. An e-mail is sent to the given e-mail address and you must reply to activate the new account. Sign In your account.



  • Under Manage Hosts click Add A Host. Select a hostname, e.g. robobot

    ev3no-ip2

    The IP address corresponds to your router's dynamic address received with DHCP from your internet provider. Click Add Host and Sign Out from no-ip.com

  • Check the new relocation service by starting Firefox or Chrome (Internet Explorer does not support authentication in a GET request). Use the URL:

    http://ev3robot:mypassword@dynupdate.no-ip.com/nic/update?hostname=robobot.zapto.org

    where mypassword is the no-ip account password.

    You get the response:

    nochg 5.149.22.50 or simply nochg

    where 5.149.22.50 is your router's address

  • Edit the properties file ev3jlib.properties in the /home/root directory of the EV3 file system. (If this file is not present, the file in the BrickGate application JAR's directory ch/aplu/ev3 is used.) Modify DucEV3Url and DucUserPass to your no-ip account username/password. The properties for the Duc looks like this:
 

# Enable/disable DUC
# Must be String (true, false)
DucEnabled = true

# URL for the update host
# Must be String
DucHostUrl = http://dynupdate.no-ip.com/nic/update

# IP alias for the EV3xxxx
# Must be String
DucEV3Url = robobot.zapto.org

# User:Password for the host authentication
# Must be String
DucUserPass = ev3robot:mypassword

# Interval in minutes between DUC requests
# when a direct client is connected
# A request is performed when DUC starts
# and when the direct EV3 client disconnects.
# Must be int
DucUpdateInterval = 30

# Interval in minutes between DUC requests
# when no direct client is connected
# Must be int
DucIdleUpdateInterval = 1

  • Start the BrickGate server. A status info at the bottom of the EV3 display tells you that the DUC is started the response it received. If the authentication to your no-ip.com account fails, you are informed that the DUC is finished. Check all DUC parameters and try again

  • As you see in ev3jlib.properties, the default DUC update interval is 30 min, if a client is connected. But in idle state the interval is as low as 1 min because the EV3 has no other work to accomplish. The response time for direct mode commands are somewhat greater than in a local area network, but still acceptable for many applications

  • Keep in mind that the socket connection uses IP port 1299. If a client sits behind a firewall that blocks this port, the link to the EV3 fails.

 

6 Developing autonomous programs with Eclipse and other IDEs

Developing autonomous programs for the EV3 is simple. For pure leJOS programs add ev3classes.jar from the leJOS distribution to your project class path (as external JAR). If, in addition to the leJOS class library, you want to use the EV3JLib class library, three additional conditions must be met to run the program successfully on the EV3:

  • You need JDK version 1.7 (or 1.6), but NOT 1.8 (or above), because the JRE on the EV3 has version 1.7
  • EV3JLibA.jar must be part of the EV3's classpath or all classes in EV3JLIBA.jar must be packed in the application JAR
  • ev3jlib.properties must reside in the EV3's application directory (user.dir), home directory (user.home) or packed in the application JAR in subfolder ch/aplu/ev3/properties

If you use our extended leJOS distribution, you have nothing special to do, because:

  • EV3JLibA.jar is part of /home/root/lejos/lib and the jrun command adds it to the classpath
  • ev3jlib.properties is part of /home/root, the home directory of the Java environment

For Eclipse a leJOS plugin is available. Check the leJOS website to see how to install it. The EV3 may be connected via USB, Bluetooth or WLAN. All you have to do is to enter the appropriate IP address in the Name field of the leJOS EV3 preferences in the Window menu item.

ev3eclipse

 

With other IDEs (Netbeans, BlueJ, Java-Editor, etc.) add ev3classes.jar from the leJOS distribution and EV3JLibA.jar from the EV3JLibA distribution to your project class path. After compilation, the Java class files have to be packed in a JAR archive with a MANIFEST.MF file that contains a Main-Class entry. Then the application JAR must be downloaded to the EV3 in the /home/lejos/programs folder and started from the leJOS menu. Packing and downloading manually is a somewhat ackward and lengthy process, but it's a one-click operation with our BrickTransfer utility.

Download BrickTransfer Utility


Example for NetBeans:

The class files reside in the <projectroot>/build/classes folder. BrickTransfer even supports a package structure. In this example MyClass.java uses the x.y package. Add EV3JLibA.jar and ev3classes.jar to the project Libraries and compile with Clean and Build. Then press the OK button in the BrickTransfer dialog.

bricktransfer

 

Example for BlueJ:

In Preferences add EV3JLibA.jar and ev3classes.jar to the user libraries.

bricktransfer1 bricktransfer2

Edit the source program and press the Compile button. The class files resides in the root of the project root. More than one application file may be used in the same project (each with a main-method). To differentiate them, set the Main Class entry to the class that you want to be executed. Of course all classes are packed and downloaded, but only one is started. The Application Name is arbitrary.

 

Example for Java-Editor (German edition):

Unter der Menü-Option Fenster | Konfiguration | Java Interpreter werden im Feld Classpath-User die beiden JARs ev3classes.jar und EV3JLibA.jar angegeben. Mit Ctrl-F9 wird die Quelldatei compiliert, danach mit BrickTransfer auf den EV3 geladen und dort ausgeführt. Es können sich mehrere Quelldateien mit je einer eigenen main-Methode im gleichen Dateiverzeichnis (hier e:\myje) befinden. Man gibt in BrickTransfer unter Main Class diejenige an, die dann auf dem EV3 gestartet werden soll. Der Application Name ist beliebig wählbar.

bricktransfer3 bricktransfer4