Stepper Motors
Stepper Motors
The unipolar stepper motor has five or six wires and four coils
(actually two coils divided by center connections on each coil).
The center connections of the coils are tied together and used as
the power connection. They are called unipolar steppers
because power always comes in on this one pole.
Bipolar stepper motors
The bipolar stepper motor usually has four wires coming out of
it. Unlike unipolar steppers, bipolar steppers have no common
center connection. They have two independent sets of coils
instead. You can distinguish them from unipolar steppers by
measuring the resistance between the wires. You should find
two pairs of wires with equal resistance. If you’ve got the leads
of your meter connected to two wires that are not connected
(i.e. not attached to the same coil), you should see infinite
resistance (or no continuity).
Two-Wire Control
Thanks to Sebastian Gassner for ideas on how to do this.
Note that the wires read from left to right. Their numbers don’t
correspond with the bit positions. For example, PORTD.3 would
be wire 1, PORTD.2 would be wire 2, PORTD.1 would be wire 3,
and PORTD.0 would be wire 4. On the BX-24, pin 9 is wire 1,
pin 10 is wire 2, and so forth.
BX-24 code:
Sub main()
call delay(0.5) ' start program with a half-
second delay
dim i as integer
motorStep(0) = bx0000_1010
motorStep(1) = bx0000_0110
motorStep(2) = bx0000_0101
motorStep(3) = bx0000_1001
do
' move motor forward 100 steps.
' note: by doing a modulo operation on i
(i mod 4),
' we can let i go as high as we want, and
thisStep
' will equal 0,1,2,3,0,1,2,3, etc. until
the end
' of the for-next loop.
for i = 1 to 100
thisStep = i mod 4
call stepMotor(thisStep)
next
End Sub
start:
High PORTB.0
TRISD = %11110000
PORTD = 255
input portb.4
Pause 1000
stepArray[0] = %00001010
stepArray[1] = %00000110
stepArray[2] =%00000101
stepArray[3] = %00001001
main:
if portb.4 = 1 then
steps = steps + 1
else
steps = steps - 1
endif
GoTo main
pBasic (Basic Stamp 2) code:
main:
steps = 200
gosub clockStep
pause 1000
gosub counterClockStep
pause 1000
goto main
clockStep:
debug "counter" , cr
for x = 0 to steps
lookup x//4, [%1010,%1001,%0101,%0110],
stepper
outs.highbyte.lownib = stepper
pause 2
next
return
counterclockStep:
debug "clockwise", cr
for x = 0 to steps
lookup x//4, [%0110,%0101,%1001,%1010],
stepper
outs.highbyte.lownib = stepper
pause 2
next
return
Wiring Code (for Arduino board):
Stepper myStepper(motorSteps,
motorPin1,motorPin2,motorPin3,motorPin4);
/*
Stepper Motor Controller
language: Wiring/Arduino
*/
#include <Stepper.h>
void setup() {
// set the motor speed at 60 RPMS:
myStepper.setSpeed(60);
// Initialize the Serial port:
Serial.begin(9600);
void loop() {
// Step forward 100 steps:
Serial.println("Forward");
myStepper.step(100);
delay(500);