Add a featured image

Python Programming for the EV3

What does programming in Python on a Linux system for the EV3 enable you to do?

  • Running a Linux system on the EV3 brick allows you to expand the functions of the EV3. Some examples include:
    • Posting to social media (FB, Twitter, etc.)
    • Sending data between multiple EV3s and interpreting data from the Internet on the EV3 brick
    • ‘Around the world’ instant communication between EV3 bricks.
  • EV3 bricks no longer have to be connected by wires to a computer, which gives users new options and a greater ease of use.

The Reasoning Behind the Project

The built-in LEGO EV3 system offers many options for LEGO programmers and has a friendly drag-and-drop interface to go with it but works with solely physical sensors and motors. Therefore it isn’t currently functional as an Internet entity or bot right out of the box. It does not use virtual data.

What do you do if you want your robot to send you a text message if it rains in Chicago?

With Python and a Linux OS system, now you can.

Diagram courtesy of Professor Ethan Danahy

A Linux system allows you to build complex, global programs that pull on any and all available digital data on the Internet, from analyzing weather reports to gathering posts with a trending hashtag to communicating with your smart devices. Similarly, the WiFi-enabled EV3 can generate virtual data.

Any of these categories of inputs and outputs can be mixed-and-matched, which allows for a plethora of new combinations of inputs and outputs (or triggers and actions like in the Event-Driven EV3 interface).

This is especially relevant for the current generation of middle school, high school and college students whose lives are increasingly tied to their digital identities. This project expands the abilities of the brick so that the only limit is the imaginations of the individuals and students using it. Now you can program your robot to post to social media, connect to websites, send emails, and much more.

Technical Details

The Linux system referenced is Debian-based, specifically Debian Jessie. The system was extensively developed by David Lechner and Ralph Hempel. The OS system Github, called ev3dev, holds all system files and extensive details. All credit to the Linux ev3dev system belongs to the two above developers as well as any other contributors.

To see all programs, tasks, notes, etc., please see my Github. These files are updated in real time. I also plan to add some of these files as attachments to this page but many files are still constantly changing.

The list of materials/supplies used are as follows:

  • EV3 LEGO brick
  • EV3 LEGO sensors and motors
  • Wifi dongle
  • MicroSD card

To see set-up instructions for the Linux system, please see my Github, also linked above.

Demonstrations

Posting to Twitter

Current State

  • All LEGO MINDSTORMS EV3 sensors and motors except for the gyroscopic sensor are implemented with wrapper functions in Python. (Note that these can also be written in C++ and Node.js.)
    • Basic functionality of these sensors and motors is completely implemented; advanced functionality is incomplete (such as 'count' or number of times pressed for the Touch Sensor)
  • LEGO sensor to digital output example
    • The EV3 can also post to Twitter when its touch sensor is pressed. It will prompt the user for the message and post it to the wall of the account it is linked to. The Python library 'tweepy' is used to facilitate this process and to handle authentication.
  • The WiFi-enabled EV3 brick has also been brought into the work done by the Event-Driven EV3 group. The EV3 can send and receive information at its own server that is sent through the interface and server hosted on a computer by the Event-Driven EV3 group, where it is processed.
    • These interactions use a set of wrapper functions that I created on top of the ev3dev system Python language bindings to make it easier for users to code in Python.
    • The collaboration with the Event-Driven EV3 group is proof that combining these wrapper functions with an interface is possible. Also, users could who wished to explore deeper could code directly in Python using these wrapper functions to control the EV3.
    • The Technical View - The process that occurs in the brick when it receives a request can be seen in the following diagram:
    • The set up above is known as 'simple brick' because the brick only processes the final commands sent to it, one command at a time.
    • An ideal 'complex brick' would do the analysis rather than the browser. It would also host its own interface (which could be the Event-Driven interface) and would only need to interact with it when it receives a new set of commands to monitor for. Otherwise, the brick would check for conditions specified by the user and react in the conditioned manner. It would be a self-sufficient brick as it would generate its own input from user input and then interpret and react to that input.

EV3 IoT + Event-Driven Programming.pdf

Future

  • Make a in-browser Python programming (or even click-and-select) interface so people can program the EV3 right from the browser
  • Have the EV3 host the interface it receives information from and have it analyze and act on this information (autonomous, 'complex' brick)
  • Connect two EV3s and an EV3 and another device with sensors (Grove Pi?) to add further sensor capabilities to the EV3
  • Have a complete system of new Python wrapper functions on top of the ev3dev python language bindings for ease of use of Python programmers, including custom actions like 'stop all,' 'post to twitter,' and 'count' (number of times touch sensor pressed since start time). The first two are implemented as well as a basic set of adaptable wrapper functions.