code runs without error, but motor is not responding yet
This commit is contained in:
parent
f93158312e
commit
f0199836d2
1 changed files with 21 additions and 24 deletions
|
|
@ -1,21 +1,19 @@
|
|||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
import board
|
||||
import time
|
||||
from adafruit_motor import stepper
|
||||
import digitalio
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
enable_pin = digitalio.DigitalInOut(board.D18)
|
||||
coil_A_1_pin = digitalio.DigitalInOut(board.D4)
|
||||
coil_A_2_pin = digitalio.DigitalInOut(board.D17)
|
||||
coil_B_1_pin = digitalio.DigitalInOut(board.D23)
|
||||
coil_B_2_pin = digitalio.DigitalInOut(board.D24)
|
||||
|
||||
enable_pin = 18
|
||||
coil_A_1_pin = 4
|
||||
coil_A_2_pin = 17
|
||||
coil_B_1_pin = 23
|
||||
coil_B_2_pin = 24
|
||||
|
||||
GPIO.setup(enable_pin, GPIO.OUT)
|
||||
GPIO.setup(coil_A_1_pin, GPIO.OUT)
|
||||
GPIO.setup(coil_A_2_pin, GPIO.OUT)
|
||||
GPIO.setup(coil_B_1_pin, GPIO.OUT)
|
||||
GPIO.setup(coil_B_2_pin, GPIO.OUT)
|
||||
|
||||
GPIO.output(enable_pin, 1)
|
||||
enable_pin.direction = digitalio.Direction.OUTPUT
|
||||
coil_A_1_pin.direction = digitalio.Direction.OUTPUT
|
||||
coil_A_2_pin.direction = digitalio.Direction.OUTPUT
|
||||
coil_B_1_pin.direction = digitalio.Direction.OUTPUT
|
||||
coil_B_2_pin.direction = digitalio.Direction.OUTPUT
|
||||
|
||||
def forward(delay, steps):
|
||||
for i in range(0, steps):
|
||||
|
|
@ -39,16 +37,15 @@ def backwards(delay, steps):
|
|||
setStep(1, 0, 1, 0)
|
||||
time.sleep(delay)
|
||||
|
||||
|
||||
def setStep(w1, w2, w3, w4):
|
||||
GPIO.output(coil_A_1_pin, w1)
|
||||
GPIO.output(coil_A_2_pin, w2)
|
||||
GPIO.output(coil_B_1_pin, w3)
|
||||
GPIO.output(coil_B_2_pin, w4)
|
||||
coil_A_1_pin.value = w1
|
||||
coil_A_2_pin.value = w2
|
||||
coil_B_1_pin.value = w3
|
||||
coil_B_2_pin.value = w4
|
||||
|
||||
while True:
|
||||
delay = raw_input("Delay between steps (milliseconds)?")
|
||||
steps = raw_input("How many steps forward? ")
|
||||
delay = input("Delay between steps (milliseconds)?")
|
||||
steps = input("How many steps forward? ")
|
||||
forward(int(delay) / 1000.0, int(steps))
|
||||
steps = raw_input("How many steps backwards? ")
|
||||
steps = input("How many steps backwards? ")
|
||||
backwards(int(delay) / 1000.0, int(steps))
|
||||
|
|
|
|||
Loading…
Reference in a new issue