Python for EV3Dev Cheat Sheet

About the Python for EV3 Shield Cheat Sheet

Resources and code fragments to help you get started coding the EV3 with Python and EV3Dev.

Links, steps, and the eventual table of contents for the CE YouTube videos on EV3Dev and Python

  1. Download the ev3dev flash card image
    http://www.ev3dev.org/docs/getting-started/

  2. Download and install Etcher (the tool to flash the card)
    https://www.etcher.io/

  3. Flash the card

  4. Insert the card into the EV3 and turn on to boot to EV3Dev

  5. Establish a network connection
    Step 5 here:
    http://www.ev3dev.org/docs/getting-started/
    I hand no success with the USB teathering and ended up using a WiFi dongle.

  6. Download and install Putty, the tool to SSH (secure shell) into the brick.
    This will allow you to control the brick from a console on your destkop.
    http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

  7. Connect to the brick using SSH, then upgrade python-ev3dev with the commands
    sudo apt-get update
        sudo apt-get install python3-ev3dev

  8. Try to edit a simple file through SSH on the brick using Nano
    Demo.... To do....

  9. Download and install Filezilla (a GUI client for copying files to the brick)
    https://filezilla-project.org/download.php?type=client

  10. Download and install Notepad++
    https://notepad-plus-plus.org/

  11. Edit a simple program using Notepad++.
    Toggle the line endings
    SFTP it to the brick using Filezilla.

    Run it on the brick using SSH

    Set the executable bit
    Run it on the brick through BrickMan. Discuss shebang.

  12. Demo of how to run a program and pipe the output to a file for debugging.

  13. Work through the examples on the Club Engineer website

  14. Supporting EV3Dev with Python docs are here:
    The best tutorial on EV3Dev & Python I have found:
    https://sites.google.com/site/ev3python/

    Python EV3Dev Docs - Not a huge help
    http://python-ev3dev.readthedocs.io/en/latest/index.html

Source Code Fragments

_run   view   |   download
_run is useful for debugging when running the py file on the EV3 causes an error to be written to the screen. _run will redirect the error text to a file called error.txt

01-beep.py   view   |   download

02-beep-windows-eol-will-fail.py   view   |   download

03-blink-leds.py   view   |   download

04-hello-world-file.py   view   |   download

05-hello-world-stdout.py   view   |   download

06-draw-lcd.py   view   |   download

07-hello-world-lcd.py   view   |   download

08-hello-world-large-font-lcd.py   view   |   download

09-display-image-bmp.py   view   |   download

club-engineer.bmp   download
You will also need to download club-engineer.bmp and copy it to the same folder as 09-display-image-bmp.py on the brick

10-read-button-state.py    view   |   download

11-wait-for-button.py   view   |   download

12-read-light-sensor-share-of-grey.py   view   |   download

13-read-light-sensor-colour.py   view   |   download

14-read-light-sensor-rgb.py   view   |   download

15-read-touch-sensor.py   view   |   download

16-read-ir-sensor.py   view   |   download

17-run-motor-duration.py   view   |   download

18-run-motor-rotations.py   view   |   download

19-run-motor-unlimited.py   view   |   download

20-run-motor-when-touch.py   view   |   download

21-write-to-file.py   view   |   download

22-read-from-file.py   view   |   download

23-stderr-to-file.py   view   |   download

24-stderr-to-file-syntax-error.py   view   |   download

25-catch-exception.py   view   |   download

26-threads.py   view   |   download

27-function-no-value-return.py   view   |   download

28-function-single-value-return.py   view   |   download

29-function-multi-value-return.py   view   |   download

30-variable-scope.py   view   |   download

31-complex-data-as-dict.py   view   |   download

32-complex-data-as-class.py   view   |   download

33-constants.py   view   |   download

34-package-simple.py   view   |   download

packagesimple.py   download
You will also need to download packagesimple.py and place it in the same folder as 34-package-simple.py

35-package-compound.py   view   |   download

packagecompound   download
You will also need to download the files in packagecompound and unzip them to a folder called packagecompound (the folder name is important as it's referenced in the code)

36-line-follow-calibrate.py   view   |   download

37-line-follow-v01.py   view   |   download

38-line-follow-v02.py   view   |   download

Toggle menu