Datasheet
while (True):
print("Single coil steps")
myStepper.step(100, Adafruit_MotorHAT.FORWARD, Adafruit_MotorHAT.SINGLE)
myStepper.step(100, Adafruit_MotorHAT.BACKWARD, Adafruit_MotorHAT.SINGLE)
print("Double coil steps")
myStepper.step(100, Adafruit_MotorHAT.FORWARD, Adafruit_MotorHAT.DOUBLE)
myStepper.step(100, Adafruit_MotorHAT.BACKWARD, Adafruit_MotorHAT.DOUBLE)
print("Interleaved coil steps")
myStepper.step(100, Adafruit_MotorHAT.FORWARD, Adafruit_MotorHAT.INTERLEAVE)
myStepper.step(100, Adafruit_MotorHAT.BACKWARD, Adafruit_MotorHAT.INTERLEAVE)
print("Microsteps")
myStepper.step(100, Adafruit_MotorHAT.FORWARD, Adafruit_MotorHAT.MICROSTEP)
myStepper.step(100, Adafruit_MotorHAT.BACKWARD, Adafruit_MotorHAT.MICROSTEP)
step() - blocking steps
As you can see above, you can step mulitple steps at a time with step()
step(numberofsteps, direction, type)
Where numbersteps is the number of steps to take, direction is either FORWARD or
BACKWARD and type is SINGLE, DOUBLE, INTERLEAVE or MICROSTEP
Note that INTERLEAVE will move half the distance of SINGLE or DOUBLE because there
are twice as many steps. And MICROSTEP will move 1/8 the distance because each
microstep counts as a step!
This is the easiest way to move your stepper but is blocking - that means that the Python
program is completely busy moving the motor. If you have two motors and you call these
two procedures in a row:
stepper1.step(100, Adafruit_MotorHAT.FORWARD, Adafruit_MotorHAT.SINGLE)
stepper2.step(100, Adafruit_MotorHAT.BACKWARD, Adafruit_MotorHAT.SINGLE)
Then the first stepper will move 100 steps, stop, and then the second stepper will start
moving.
Chances are you'd like to have your motors moving at once!
For that, you'll need to take advantage of Python's ability to multitask with threads which
you can see in DualStepperTest.py
The key part of the DualStepperTest example code is that we define a function that will act
as a 'wrapper' for the step() procedure:
def stepper_worker(stepper, numsteps, direction, style):
© Adafruit Industries
https://learn.adafruit.com/adafruit-dc-and-stepper-motor-hat-for-
raspberry-pi
Page 30 of 38










