You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: motors.md
+19-19Lines changed: 19 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
Motors are great for physical computing: they allow you to turn a wheel forwards and backwards, or make something spin around.
4
4
5
-
A motor cannot be controlled directly from the Raspberry Pi's GPIO pins, because it needs a variable supply of 5 volts. This means you need to power it separately. However, motor controller add-on boards can be used to provide this functionality.
5
+
A motor can't be controlled directly from the Raspberry Pi's GPIO pins, because it needs a variable supply of 5 volts. This means you need to power it separately. However, motor controller add-on boards can be used to provide this functionality.
6
6
7
7
In this guide, you'll be controlling two motors from your Raspberry Pi using Python on the desktop. First, it's best just to learn how to control the motor. Then, once you have it working, you could easily use your code to drive a Raspberry Pi-powered robot by detaching the monitor, mouse, and keyboard and building a robot around a chassis.
8
8
@@ -22,13 +22,13 @@ You'll need to wire up two motors and your battery pack using the motor controll
22
22
23
23

24
24
25
-
1. You'll need to know which GPIO pins your motor controller uses. Refer to the board's documentation. This will usually be described as Motor A and Motor B, or MA1, MA2, MB1 and MB2. Make a note of these pin numbers. If you're not sure which is which, you can investigate this next.
25
+
1. You'll need to know which GPIO pins your motor controller uses. Refer to the board's documentation. This will usually be described as Motor A and Motor B, or MA1, MA2, MB1, and MB2. Make a note of these pin numbers. If you're not sure which is which, you can investigate this next.
26
26
27
-
## Output Devices
27
+
## Output devices
28
28
29
29
First, you should learn to control motors by controlling the pins individually.
30
30
31
-
1. Boot the Pi and open Python 3
31
+
1. Boot the Pi and open Python 3.
32
32
33
33
1. In the shell, enter the following line to import `OutputDevice` from the GPIO Zero library:
34
34
@@ -51,7 +51,7 @@ First, you should learn to control motors by controlling the pins individually.
51
51
a.on()
52
52
```
53
53
54
-
The motor should now be spinning! If not, check you are addressing the right pin numbers. The two pins should be connected to the same motor. Also check your wiring and your batteries.
54
+
The motor should now be spinning! If not, check you are addressing the right pin numbers. The two pins should be connected to the same motor. Also, check your wiring and your batteries.
55
55
56
56

57
57
@@ -114,7 +114,7 @@ First, you should learn to control motors by controlling the pins individually.
114
114
115
115
## PWM
116
116
117
-
So far, you have used simple on/off commands to control your motors. PWM (Pulse-width modulation) allows you to control the speed. The `on()` function sets the motor to go at full speed, but you can control this to make the motor go at a fraction of this speed.
117
+
So far, you have used simple on/off commands to control your motors. PWM (pulse-width modulation) allows you to control the speed. The `on()` function sets the motor to go at full speed, but you can control this to make the motor go at a fraction of this speed.
118
118
119
119
1. Since you're going to reuse the same pins in a different way, you'll have to close the connections to the pins. The easiest way to do that is to restart the Python shell by clicking **Shell > Restart shell**.
120
120
@@ -124,7 +124,7 @@ So far, you have used simple on/off commands to control your motors. PWM (Pulse-
124
124
from gpiozero import PWMOutputDevice
125
125
```
126
126
127
-
1. Create new connections to each of your pins,as before, but using `PWMOutputDevice`:
127
+
1. Create new connections to each of your pins as before, but using `PWMOutputDevice`:
128
128
129
129
```python
130
130
a = PWMOutputDevice(4)
@@ -141,7 +141,7 @@ So far, you have used simple on/off commands to control your motors. PWM (Pulse-
141
141
142
142
The motor should now be spinning at half speed.
143
143
144
-
1. To turn the motor the opposite direction, turn `a` off (orset its value to `0`) andset`b`'s value to `0.5`:
144
+
1. To turn the motor inthe opposite direction, turn `a` off (orset its value to `0`) andset`b`'s value to `0.5`:
145
145
146
146
```python
147
147
a.value = 0
@@ -173,15 +173,15 @@ So far, you have used simple on/off commands to control your motors. PWM (Pulse-
173
173
174
174
The motors should now speed up from0 (stopped) to 0.1, 0.2and up to 1.
175
175
176
-
Be aware, though, that the motor may not move until it gets above a certain speed as there may not be enough power to engage it.
176
+
Be aware, though, that the motor may not move until it gets above a certain speed,as there may not be enough power to engage it.
177
177
178
178
## Motor class
179
179
180
-
Now you've learned how setting pins high and low can control a motor, you should proceed to using the built-in `Motor` class, which has all the functionality you just learned about, provided in a simple way, including PWM for speed.
180
+
Now you've learned how setting pins high and low can control a motor, you should proceed to using the built-in `Motor` class; this has all the functionality you just learned about, provided in a simple way, including PWM for speed.
181
181
182
182

183
183
184
-
1. Restart the shell again (**Ctrl + F6**)
184
+
1. Restart the shell again (**Ctrl + F6**).
185
185
186
186
1. Import the `Motor`class:
187
187
@@ -198,7 +198,7 @@ Now you've learned how setting pins high and low can control a motor, you should
198
198
199
199
Note: to make it easier to see which pin is which, you can use `Motor(forward=4, backward=14)`for future reference.
200
200
201
-
1. Now drive one of the motors forward using:
201
+
1. Now drive one of the motors forward using the following code:
202
202
203
203
```python
204
204
motor1.forward()
@@ -217,7 +217,7 @@ Now you've learned how setting pins high and low can control a motor, you should
217
217
motor2.backward(0.5)
218
218
```
219
219
220
-
1. The `Motor`class also allows you to reverse the motor's direction. Try using this a loop:
220
+
1. The `Motor`class also allows you to reverse the motor's direction. Try using this loop:
221
221
222
222
```python
223
223
motor1.forward()
@@ -228,7 +228,7 @@ Now you've learned how setting pins high and low can control a motor, you should
228
228
motor2.reverse()
229
229
```
230
230
231
-
This will make the motors spin in opposite directions, then switching every five seconds. Press **Ctrl + C** to exit the loop.
231
+
This will make the motors spin in opposite directions, then switch every five seconds. Press **Ctrl + C** to exit the loop.
232
232
233
233
1. Now stop the motors:
234
234
@@ -239,11 +239,11 @@ Now you've learned how setting pins high and low can control a motor, you should
239
239
240
240
## Robot class
241
241
242
-
If you had a robot with two wheels, you would want to control the two motors together, rather than separately, just like you did for the two pins of each motor. Luckily, there's also a `Robot` class in GPIO Zero.
242
+
If you had a robot with two wheels you would want to control the two motors together, rather than separately, just like you did for the two pins of each motor. Luckily, there's also a `Robot` class in GPIO Zero.
243
243
244
244

245
245
246
-
1. Restart the shell again (**Ctrl + F6**)
246
+
1. Restart the shell again (**Ctrl + F6**).
247
247
248
248
1. Import the `Motor`class:
249
249
@@ -259,7 +259,7 @@ If you had a robot with two wheels, you would want to control the two motors tog
259
259
260
260
Note: to make it easier to see which pin is which, you can use `Robot(left=(4, 14), right=(17, 27))`for future reference.
261
261
262
-
1. Now drive one of the motors forward using:
262
+
1. Now drive one of the motors forward using the following code:
263
263
264
264
```python
265
265
robot.forward()
@@ -311,5 +311,5 @@ If you had a robot with two wheels, you would want to control the two motors tog
311
311
312
312
Now you've learned how motors work, why not try:
313
313
314
-
- Making your own robot with our [Build a robot](http://raspberrypi.org/learning/robo-butler/) resource
315
-
-Make a [spinning flower wheel](http://raspberrypi.org/learning/spinning-flower-wheel/)
314
+
- Making your own robot with our [Build a robot](http://raspberrypi.org/learning/robo-butler/) resource?
315
+
-Making a [spinning flower wheel](http://raspberrypi.org/learning/spinning-flower-wheel/)?
0 commit comments