/ examples / motor_stepper_digitalio.py
motor_stepper_digitalio.py
 1  # Use this example for digital pin control of an H-bridge driver
 2  # like a TB6612 or L298N.
 3  
 4  import time
 5  import board
 6  import digitalio
 7  from adafruit_motor import stepper
 8  
 9  DELAY = 0.01
10  STEPS = 200
11  
12  coils = (
13      digitalio.DigitalInOut(board.D19),  # A1
14      digitalio.DigitalInOut(board.D26),  # A2
15      digitalio.DigitalInOut(board.D20),  # B1
16      digitalio.DigitalInOut(board.D21),  # B2
17  )
18  
19  for coil in coils:
20      coil.direction = digitalio.Direction.OUTPUT
21  
22  motor = stepper.StepperMotor(coils[0], coils[1], coils[2], coils[3], microsteps=None)
23  
24  for step in range(STEPS):
25      motor.onestep()
26      time.sleep(DELAY)
27  
28  for step in range(STEPS):
29      motor.onestep(direction=stepper.BACKWARD)
30      time.sleep(DELAY)
31  
32  for step in range(STEPS):
33      motor.onestep(style=stepper.DOUBLE)
34      time.sleep(DELAY)
35  
36  for step in range(STEPS):
37      motor.onestep(direction=stepper.BACKWARD, style=stepper.DOUBLE)
38      time.sleep(DELAY)
39  
40  for step in range(STEPS):
41      motor.onestep(style=stepper.INTERLEAVE)
42      time.sleep(DELAY)
43  
44  for step in range(STEPS):
45      motor.onestep(direction=stepper.BACKWARD, style=stepper.INTERLEAVE)
46      time.sleep(DELAY)
47  
48  motor.release()