Hardware Reference
In-Depth Information
var
states
= [[
1
,
0
,
0
,
0
], [
0
,
1
,
0
,
0
], [
0
,
0
,
1
,
0
], [
0
,
0
,
0
,
1
]];
Whenever you step, you just index the next element in the array. If you want to go back-
ward, index the previous element.
There are two other state sequences given in the code, but they aren't ever used.
statesHiTorque
is like the original
states
, except that it has both magnets on at
the same time, giving a stronger pull on the motor. The
statesHalfStep
alternates
between having one and two coils on simultaneously to give finer control in the step size:
var
statesHiTorque
= [[
1
,
1
,
0
,
0
], [
0
,
1
,
1
,
0
], [
0
,
0
,
1
,
1
], [
1
,
0
,
0
,
1
]];
var
statesHalfStep
= [[
1
,
0
,
0
,
0
], [
1
,
1
,
0
,
0
], [
0
,
1
,
0
,
0
], [
0
,
1
,
1
,
0
],
[
0
,
0
,
1
,
0
], [
0
,
0
,
1
,
1
], [
0
,
0
,
0
,
1
], [
1
,
0
,
0
,
1
]];
You can easily try either of these by assigning them to the
states
variable.
outputs 3.3 V on its GPIO pins, but the stepper motor I am using really needs 5 V. Con-
necting the 5 V in this way provides 5 V out of the L293D to the stepper motor.
NOTE
If your stepper motor requires a higher voltage (up to 12 V), you can wire an external power
supply, as shown in
Figure 4-10
.