Hardware Reference
In-Depth Information
Solution
Use an L293D H-bridge. The bipolar stepper motor requires us to reverse the coils, so we
need to use an H-bridge.
Here's what you will need:
▪ Breadboard and jumper wires (see
“Prototyping Equipment”
)
▪ 3 V to 5 V bipolar stepper motor (see
“Miscellaneous”
)
▪ L293D H-Bridge IC (see
“Integrated Circuits”
)
Wire as shown in
Figure 4-8
.
Figure 4-8. Bipolar stepper motor wiring
Use the code in
Example 4-4
(
bipolarStepperMotor.js
) to drive the motor.
Example 4-4. Driving a bipolar stepper motor (bipolarStepperMotor.js)
#!/usr/bin/env node
var
b
=
require
(
'bonescript'
);
// Motor is attached here
var
controller
= [
"P9_11"
,
"P9_13"
,
"P9_15"
,
"P9_17"
];
var
states
= [[
1
,
0
,
0
,
0
], [
0
,
1
,
0
,
0
], [
0
,
0
,
1
,
0
], [
0
,
0
,
0
,
1
]];
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
]];
var
curState
=
0
;
// Current state
var
ms
=
100
,
// Time between steps, in ms
max
=
22
,
// Number of steps to turn before turning around
min
=
0
;
// Minimum step to turn back around on