@@ -22,10 +22,9 @@ Getting Started
22
22
23
23
This library runs on ev3dev _. Before continuing, make sure that you have set up
24
24
your EV3 or other ev3dev device as explained in the `ev3dev Getting Started guide `_.
25
- Make sure that you have a kernel version that includes ``-10-ev3dev `` or higher (a
26
- larger number). You can check the kernel version by selecting "About" in Brickman
27
- and scrolling down to the "kernel version". If you don't have a compatible version,
28
- `upgrade the kernel before continuing `_.
25
+ Make sure you have an ev3dev-stretch version greater than ``2.2.0 ``. You can check
26
+ the kernel version by selecting "About" in Brickman and scrolling down to the
27
+ "kernel version". If you don't have a compatible version, `upgrade the kernel before continuing `_.
29
28
30
29
Usage
31
30
-----
@@ -41,15 +40,16 @@ your own solution. If you don't know how to do that, you are probably better off
41
40
choosing the recommended option above.
42
41
43
42
The template for a Python script
44
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
43
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45
44
46
45
Every Python program should have a few basic parts. Use this template
47
46
to get started:
48
47
49
48
.. code-block :: python
50
49
51
50
# !/usr/bin/env python3
52
- from ev3dev2.motor import LargeMotor, OUTPUT_A , SpeedPercent
51
+ from ev3dev2.motor import LargeMotor, OUTPUT_A , OUTPUT_B , SpeedPercent, MoveTank
52
+ from ev3dev2.sensor import INPUT_1
53
53
from ev3dev2.sensor.lego import TouchSensor
54
54
from ev3dev2.led import Leds
55
55
@@ -64,6 +64,10 @@ or additional utilities.
64
64
65
65
You should use the ``.py `` extension for your file, e.g. ``my-file.py ``.
66
66
67
+ If you encounter an error such as ``/usr/bin/env: 'python3\r': No such file or directory ``,
68
+ you must switch your editor's "line endings" setting for the file from "CRLF" to just "LF".
69
+ This is usually in the status bar at the bottom. For help, see `our FAQ page `_.
70
+
67
71
Important: Make your script executable (non-Visual Studio Code only)
68
72
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
69
73
@@ -80,7 +84,7 @@ from the command line by preceding the file name with ``./``: ``./my-file.py``
80
84
Controlling the LEDs with a touch sensor
81
85
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
82
86
83
- This code will turn the left LED red whenever the touch sensor is pressed, and
87
+ This code will turn the LEDs red whenever the touch sensor is pressed, and
84
88
back to green when it's released. Plug a touch sensor into any sensor port before
85
89
trying this out.
86
90
@@ -89,11 +93,21 @@ trying this out.
89
93
ts = TouchSensor()
90
94
leds = Leds()
91
95
96
+ print (" Press the touch sensor to change the LED color!" )
97
+
92
98
while True :
93
99
if ts.is_pressed:
94
- leds.set_color(leds.led_groups.LEFT , leds.led_colors.GREEN )
100
+ leds.set_color(" LEFT" , " GREEN" )
101
+ leds.set_color(" RIGHT" , " GREEN" )
95
102
else :
96
- leds.set_color(leds.led_groups.LEFT , leds.led_colors.RED )
103
+ leds.set_color(" LEFT" , " RED" )
104
+ leds.set_color(" RIGHT" , " RED" )
105
+
106
+ If you'd like to use a sensor on a specific port, specify the port like this:
107
+
108
+ .. code-block :: python
109
+
110
+ ts = TouchSensor(INPUT_1 )
97
111
98
112
Running a single motor
99
113
~~~~~~~~~~~~~~~~~~~~~~
@@ -144,7 +158,7 @@ If you want to make your robot speak, you can use the ``Sound.speak`` method:
144
158
from ev3dev2.sound import Sound
145
159
146
160
sound = Sound()
147
- sound.speak(' Welcome to the E V 3 dev project!' ).wait()
161
+ sound.speak(' Welcome to the E V 3 dev project!' )
148
162
149
163
Make sure to check out the `User Resources `_ section for more detailed
150
164
information on these features and many others.
@@ -192,7 +206,7 @@ to type the password (the default is ``maker``) when prompted.
192
206
.. code-block :: bash
193
207
194
208
sudo apt-get update
195
- sudo apt-get install --only-upgrade python3-ev3dev
209
+ sudo apt-get install --only-upgrade python3-ev3dev2
196
210
197
211
198
212
Developer Resources
@@ -209,9 +223,6 @@ Python 2.x and Python 3.x Compatibility
209
223
Some versions of the ev3dev _ distribution come with both `Python 2.x `_ and `Python 3.x `_ installed
210
224
but this library is compatible only with Python 3.
211
225
212
- As of the 2016-10-17 ev3dev image, the version of this library which is included runs on
213
- Python 3 and this is the only version that will be supported from here forward.
214
-
215
226
.. _ev3dev : http://ev3dev.org
216
227
.. _ev3dev.org : ev3dev _
217
228
.. _Getting Started : ev3dev-getting-started _
@@ -221,9 +232,10 @@ Python 3 and this is the only version that will be supported from here forward.
221
232
.. _detailed instructions for USB connections : ev3dev-usb-internet _
222
233
.. _via an SSH connection : http://www.ev3dev.org/docs/tutorials/connecting-to-ev3dev-with-ssh/
223
234
.. _ev3dev-usb-internet : http://www.ev3dev.org/docs/tutorials/connecting-to-the-internet-via-usb/
224
- .. _our Read the Docs page : http://python-ev3dev.readthedocs.org/en/stable /
235
+ .. _our Read the Docs page : http://python-ev3dev.readthedocs.org/en/ev3dev-stretch /
225
236
.. _ev3python.com : http://ev3python.com/
226
- .. _FAQ : http://python-ev3dev.readthedocs.io/en/stable/faq.html
237
+ .. _FAQ : http://python-ev3dev.readthedocs.io/en/ev3dev-stretch/faq.html
238
+ .. _our FAQ page : FAQ _
227
239
.. _ev3dev-lang-python : https://github.com/rhempel/ev3dev-lang-python
228
240
.. _our Issues tracker : https://github.com/rhempel/ev3dev-lang-python/issues
229
241
.. _EXPLOR3R : demo-robot _
0 commit comments