Lego EV3 and Python programming language

LEGO Mindstorms EV3 is awesome and with ev3dev is super awesome – that is the slogan of the Debian Linux distribution customized for EV3.

The authors had taken the Linux kernel from LEGO, they upgraded to v3.16, added a range of hardware drivers, so the EV3 with ev3dev allows you to connect a wide range of USB WiFi adapters, Bluetooth keyboards and gamepads, USB audio players, etc. Processor ARM9 in EV3 is supported by the Debian platform, and so you can add new software in the usual way: sudo apt-get install xyz.

Programming EV3 in Python

The Library for Python language and ev3dev is on the GitHub, but for comfortable programming directly from the browser (so even from a Tablet), and for the immediate execution of code is useful to add support interactive IPython with Jupyter notebooks.

Preparatory work:

  1. microSD card with ev3dev
  2. connection EV3 brick with a Windows PC
  3. installation of the programming support in Python
  4. running the notebook server on the EV3 brick
  5. programming in Python

microSD card with ev3dev

Let’s copy the image of the operating system ev3dev on the microSD card (max. 32 GB).
Each edition are for the download on the GitHub. Currently they bear the title ev3-ev3dev-jessie….
You can copy the downloaded image on the microSD card using, for example, by the Win32 Disk Imager.

You put prepared microSD card into the slot of the switched off Lego EV3 brick and then you can turn the brick on.

Connection EV3 brick with a Windows PC

The EV3 brick we will connect with PC by the USB cable. Thanks to the RNDIS we will use the cable for networking. Through it the EV3 brick gets to the internet.

Instructions “How to connect” are clearly described on ev3dev.org.

After a successful installation of the RNDIS driver, we will prepare on the PC shared connection to the Internet: Control Panel > Network and Sharing Center > Change adapter settings >> right click on Internet connection, Properties > Sharing tab > Allow other network users to connect through this computer’s Internet connection.
This way we create the gateway (RNDIS connection) with IPv4 address of 192.168.137.1.

On the EV3 brick we will set properties for IPv4 protocol.
Wireless and Networks > All Network Connections > Wired > IPv4; Change; Load Windows Defaults.
So the EV3 brick gets the address of 192.168.137.3.

Verify the connection with the EV3 brick. Open the Command prompt on the PC and type:
ping 192.168.137.3

Installation of the programming support in Python

We will log in to the EV3 brick as to the remote computer. We use the Telnet and SSH client PuTTy.

In PuTTy you type in the field Host name: 192.168.137.3 | Port: 22 | press Open.

After a while pops up a prompt to log on:
login as:
Type: robot
You will be prompted for a password:
robot@192.168.137.3's password:
Type: maker

We will get access to all “super-user” options:
sudo su
Repeat the password:
[sudo] password for robot:
Enter: maker
Following this we operating with command-line interpreter on the ev3dev.

Add a name server to use symbolic addresses on the Internet.
We modify the file with name servers:
nano /etc/resolv.conf
…and we adding e. g. the address of the home router through which you connect to the Internet:
nameserver 192.168.1.1

Then we update informations about the system Debian Jessie:
apt-get update

Installation of the Python3 support:
apt-get install python3-pil
python3 -m easy_install python-ev3dev
…and then installation of the Python interpreter:
apt-get install ipython-notebook

Running the notebook server on the EV3 brick

After installation (it will take some time), we can start the IPython server on the EV3:
ipython notebook --no-browser --ip=* --port=8889

If you wish to start the server automatically with starting the EV3 brick, you can add command to the automatically running tasks.

We will create a file with the “script”:
sudo nano /etc/init.d/ipev3
……and type:
#! /bin/sh # /etc/init.d/ipev3 ipython notebook --no-browser --ip=* --port=8889

We set the permissions to the file:
chmod 755 /etc/init.d/ipev3
…and we update the task list:
update-rc.d ipev3 defaults

Programming in Python

We launch the Internet browser on the PC and open the page with the IPython notebooks:
http://192.168.137.3:8889

contribute:
Lego EV3