Python Language Bindings For Ev3dev - Python-Ev3dev 0.6.0
Python Language Bindings For Ev3dev - Python-Ev3dev 0.6.0
If you havent written code in Python before, youll need to learn the language before you can use
this library. TODO: INSERT RESOURCES HERE
Getting Started
This library runs on ev3dev (http://ev3dev.org). Before continuing, make sure that you have set up
your EV3 or other ev3dev device as explained in the ev3dev Getting Started guide
(http://www.ev3dev.org/docs/getting-started/). Make sure that you have a kernel version that
includes -10-ev3dev or higher (a larger number). You can check the kernel version by selecting
About in Brickman and scrolling down to the kernel version. If you dont have a compatible
version, upgrade the kernel rst. TODO: INSERT LINK HERE
Once you have booted ev3dev and connected to your EV3 (or Raspberry Pi / BeagleBone) via SSH,
you will need to install the latest version of this library.
To do so, run the following commands, which could take ten minutes or longer (you may be
prompted to type the password; the default is maker):
sudoaptgetupdate
sudoaptgetinstallpython3ev3dev
Now that you have the latest version installed, you should be ready to start using ev3dev with
Python. If you want to go through some basic usage examples, check out the Usage Examples
section to try out motors, sensors and LEDs. Then look at Writing Python Programs for Ev3dev to
see how you can save your Python code to a le.
Make sure that you look at the User Resources section as well for links to documentation and
larger examples.
Usage Examples
To run these minimal examples, run the Python3 interpreter from the terminal using the python3
command:
The >>> characters are the default prompt for Python. In the examples below, we have removed
these characters so its easier to cut and paste the code into your session.
importev3dev.ev3asev3
Running a motor
Now plug a motor into the A port and paste this code into the Python prompt. This little program
will run the motor at 500 ticks per second (around 0.4 rotations per second) for three seconds.
m=ev3.LargeMotor('outA')
m.run_timed(time_sp=3000,speed_sp=500)
Using text-to-speech
If you want to make your robot speak, you can use the Sound.speak method:
ev3.Sound.speak('WelcometotheEV3devproject!').wait()
The rst two lines should be included in every Python program you write for ev3dev. The rst
allows you to run this program from Brickman, while the second imports this library.
When saving Python les, it is best to use the .py extension, e.g. myfile.py .
User Resources
Library Documentation
v:latest
Class documentation for this library can be found on our Read the Docs page (http://pythonev3dev.readthedocs.org/en/latest/) . You can always go there to get information on how you can
use this librarys functionality.
ev3dev.org
ev3dev.org (http://ev3dev.org) is a great resource for nding guides and tutoials on using ev3dev.
Support
If you are having trouble using this library, please open an issue at our Issues tracker
(https://github.com/rhempel/ev3dev-lang-python/issues) so that we can help you. When opening
an issue, make sure to include as much information as possible about what you are trying to do
and what you have tried. The issue template is in place to guide you through this process.
Demo Robot
Laurens Valk of robot-square (http://robotsquare.com/) has been kind enough to allow us to
reference his excellent EXPLOR3R (http://robotsquare.com/2015/10/06/explor3r-buildinginstructions/) robot. Consider building the EXPLOR3R
(http://robotsquare.com/2015/10/06/explor3r-building-instructions/) and running the demo
programs referenced below to get familiar with what Python programs using this binding look like.
Demo Code
There are demo programs (https://github.com/rhempel/ev3dev-lang-python/tree/master/demo)
that you can run to get acquainted with this language binding. The programs are designed to work
with the EXPLOR3R (http://robotsquare.com/2015/10/06/explor3r-building-instructions/) robot.
Developer Resources
Python Package Index
The Python language has a package repository (https://pypi.python.org/pypi) where you can nd
libraries that others have written, including the latest version of this package
(https://pypi.python.org/pypi/python-ev3dev).
The ev3dev Binding Specication
Like all of the language bindings for ev3dev (http://ev3dev.org) supported hardware, the Python
binding follows the minimal API that must be provided per this document
(https://github.com/ev3dev/ev3dev-lang/blob/develop/wrapper-specication.md).
The ev3dev-lang Project on GitHub
The source repository for the generic API (https://github.com/ev3dev/ev3dev-lang) and the scripts
to automatically generate the binding. Only developers of the ev3dev-lang-python
(https://github.com/rhempel/ev3dev-lang-python) binding would normally need to access this
information.
Until then, you must follow the instructions at the top of this README to make sure that you have
installed the newest version of the Python 3-based library.
Contents
API reference (spec.html)
Motor classes (motors.html)
Tacho motor (motors.html#tacho-motor)
Large EV3 Motor (motors.html#large-ev3-motor)
Medium EV3 Motor (motors.html#medium-ev3-motor)
DC Motor (motors.html#dc-motor)
Servo Motor (motors.html#servo-motor)
Sensor classes (sensors.html)
Sensor (sensors.html#sensor)
Special sensor classes (sensors.html#special-sensor-classes)
Other classes (other.html)
Leds (other.html#leds)
Power Supply (other.html#power-supply)
Button (other.html#button)
Sound (other.html#sound)
Screen (other.html#screen)
Lego Port (other.html#lego-port)
Back to top
v:latest