Hi,
I'm working on controlling a bipolar stepper motor with the Raspberry pi using python scripts. I want to rotate the motor a specific set of degrees for a full 360 degree rotation. For example rotate the motor 11,25 degrees at a time a total of 32 times for a full rotation.
I have all the connections set up, but when I rund a script I found online the motor goes crazy, rotating uncontrollably in both directions.
Can someone point me in the right direction? The scripts I used is:
I'm working on controlling a bipolar stepper motor with the Raspberry pi using python scripts. I want to rotate the motor a specific set of degrees for a full 360 degree rotation. For example rotate the motor 11,25 degrees at a time a total of 32 times for a full rotation.
I have all the connections set up, but when I rund a script I found online the motor goes crazy, rotating uncontrollably in both directions.
Can someone point me in the right direction? The scripts I used is:
Code
import RPi.GPIO as GPIO
import time
# Variables
delay = 0.0055
steps = 500
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
# Enable pins for IN1-4 to control step sequence
coil_A_1_pin = 18
coil_A_2_pin = 23
coil_B_1_pin = 24
coil_B_2_pin = 25
# Set pin states
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)
# Function for step sequence
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)
# loop through step sequence based on number of steps
for i in range(0, steps):
setStep(1,0,1,0)
time.sleep(delay)
setStep(0,1,1,0)
time.sleep(delay)
setStep(0,1,0,1)
time.sleep(delay)
setStep(1,0,0,1)
time.sleep(delay)
# Reverse previous step sequence to reverse motor direction
for i in range(0, steps):
setStep(1,0,0,1)
time.sleep(delay)
setStep(0,1,0,1)
time.sleep(delay)
setStep(0,1,1,0)
time.sleep(delay)
setStep(1,0,1,0)
time.sleep(delay)

