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
+6-10Lines changed: 6 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,10 @@ In this guide, you'll be controlling two motors from your Raspberry Pi using Pyt
10
10
11
11
A motor comprises two pins: positive and negative. If a 5V supply is provided to the positive pin, and 0V (ground) to the negative, it will drive forwards. If 0V is provided to the positive, and 5V to the negative, it will drive backwards. If no voltage is provided, the motor will stop.
12
12
13
+

14
+
15
+
*Image credit: [Wikipedia](https://en.wikipedia.org/wiki/H_bridge), CC BY-SA*
16
+
13
17
## Wiring
14
18
15
19
You'll need to wire up two motors and your battery pack using the motor controller.
@@ -18,9 +22,9 @@ You'll need to wire up two motors and your battery pack using the motor controll
18
22
19
23

20
24
21
-
1. Connect a battery pack to the power ports of the motor controller, connecting the positive (red) battery wire to the positive (+) power terminal on the motor controller, and the negative (black) battery wire to the negative (-) power terminal on the motor controller:
25
+
1. Connect a battery pack to the power ports of the motor controller, connecting the positive (red) battery wire to the positive (+) power terminal on the motor controller, and the negative (black) battery wire to the negative (-) power terminal on the motor controller, and connect two motors:
22
26
23
-

27
+

24
28
25
29
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
30
@@ -53,8 +57,6 @@ First, you should learn to control motors by controlling the pins individually.
53
57
54
58
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
59
56
-

57
-
58
60
1. Now try turning that pin off, and turning the other pin on:
59
61
60
62
```python
@@ -64,8 +66,6 @@ First, you should learn to control motors by controlling the pins individually.
64
66
65
67
The motor should now be spinning in the opposite direction.
66
68
67
-

68
-
69
69
1. To stop the motor, just make sure both motors are off:
70
70
71
71
```python
@@ -179,8 +179,6 @@ So far, you have used simple on/off commands to control your motors. PWM (pulse-
179
179
180
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
-

183
-
184
182
1. Restart the shell again (**Ctrl + F6**).
185
183
186
184
1. Import the `Motor`class:
@@ -241,8 +239,6 @@ Now you've learned how setting pins high and low can control a motor, you should
241
239
242
240
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.
0 commit comments