Introduction

Stop Press: If you use MobaXTerm then please read about a possible bug.

Stop Press: On March 20 2017 I published another YouTube video, this time looking at a variety of possible workflows for programming the EV3 with EV3 Python. See it on the Workflows pageFor other news please see the news page.

This site, which can be reached at www.ev3python.com, is intended to help users of the Lego EV3 robot who are already familiar with the basics of programming in Python to begin using the EV3 Python programming language to control their robot.

The Lego Mindstorms EV3 robot is a very popular educational / entertainment robot that is normally programmed using an icon-based programming system that resembles Scratch. Read more about icon-based Lego EV3 programming on my site mind-storms.com. But the EV3 has a Linux computer at its heart and can therefore be programmed using a number of other programming systems such as Python, C++, Java or EV3 Basic (see my site ev3basic.com). Running these more advanced programming languages allows you to get your EV3 robot to do things that would not be possible with the standard EV3 programming system, such as make this drawing robot which uses EV3 Python:


This site is not intended to show you how to make programs as complex as the one above, only to help you get started with EV3 programming by working with very short, simple, easy-to-understand programs. But maybe one day you will be able to make your own programs as impressive as the one above.

If you are not sure which programming system you should be using to program the EV3 then follow this link. If you are sure that you want to use Python to program the EV3 then read on...

You're probably curious about what an EV3 Python program looks like. Here is an example which uses a color sensor to help a rover-type vehicle to follow a black line. This is just to give you a glimpse of an EV3 Python script - the full explanation is on THIS PAGE. This program does however include comments (preceded each time by an '#' sign) which are there solely to help you understand the code.

#!/usr/bin/env python3
from ev3dev.ev3 import *

btn = Button() # will use any button to stop script

# Connect EV3 color sensor.
cl = ColorSensor() 

# Put the color sensor into COL-REFLECT mode
# to measure reflected light intensity.
cl.mode='COL-REFLECT'

# Attach large motors to ports B and C
mB = LargeMotor('outB')
mC = LargeMotor('outC')

while not btn.any():    # exit loop when any button pressed
    if cl.value()<30:   # weak reflection so over black line
        # medium turn right
        mB.run_forever(speed_sp=450)
        mC.stop(stop_action='brake')
    else:   # strong reflection (>=30) so over white surface
        # medium turn left
        mB.stop(stop_action='brake')
        mC.run_forever(speed_sp=450)
      
mB.stop(stop_action='brake')
mC.stop(stop_action='brake')

EV3 Python needs to run on top of the EV3dev operating system. The official site of EV3dev and EV3 Python is www.ev3dev.org and I will refer you to that site for the details of the installation and the documentation of the various EV3 Python functions. The developers of EV3dev and EV3 Python have done a fantastic job making available a stable operating system and robot-related Python commands with the simplest possible syntax. By the way, be aware that the 'official' EV3 Python described on this site should not be confused with an alternate version, Topikachu's 'Python EV3'. If you choose to use the official EV3 Python then you should ignore anything you find online that refers to the Topikachu version, to avoid confusion.

Unlike the developers of EV3dev, I'm not an expert on Linux, EV3Dev or EV3 Python, just a beginner who hopes to provide assistance to people like myself who are just getting started with EV3 Python programming. This site is in no way endorsed by Lego Corporation.

I am a Windows man, so this site will be oriented towards users of Windows, but users of other platforms should also find the site useful. This site is designed to be compatible with both types of EV3 robot kit (home edition and education edition). In fact this site will only discuss what can be achieved with the standard Lego hardware - there will be no discussion of third party hardware. Having said that, it's good to know that it should be possible to use EV3dev and EV3 Python with third-party sensors and motors and even run EV3 Python on other platforms in addition to the EV3, such as Raspberry Pi with either the BrickPi shield or the PiStorms shield. These 'shields' plug into the Raspberry Pi and act as an interface between the Raspberry Pi and Lego EV3 motors and sensors. This means you can use the extra power of the Pi compared to the EV3 and in the case of PiStorms you also get a nice color screen. See HERE.

Now that you understand what this site is about, the next step is for you to install EV3Dev and EV3 Python.
Subpages (2): News Why EV3 Python?
Comments