2 A4988's, 2 Motors, RPI, Duplicated Movement

I have two motors and two A4988s and each has it’s own stepper motor, being driven by the same PSU and RPI. The motors work great, except for the fact that any movement I make to one is copied to the other even though they are using unique GPIO pins for step and direction off of the raspberry pi.

Temporarily I am going to add some transistors that I can use to control which pins are active, but this is going to use extra GPIO pins and I like to keep things as simple as possible. I have step down resistors on both step pins, I’m not sure if this could be a contributing factor.

I am using a modified python script (original found here: https://www.raspberrypi.org/forums/viewtopic.php?t=110368) that you can see below:

import sys
import RPi.GPIO as gpio
import time
 
#Read arguements
try: 
    direction = sys.argv[1]
    steps = int(float(sys.argv[2]))
    motor = int(sys.argv[3])
except:
    steps = 0

print("You told me to turn %s %s steps.") % (direction, steps)

#Setup the raspberry pi's GPIOs
gpio.setmode(gpio.BCM)
gpio.setup(23, gpio.OUT) #GPIO23 = Direction for motor 0
gpio.setup(24, gpio.OUT) #GPIO24 = Step for motor 0

gpio.setup(27, gpio.OUT) #GPIO27 = Direction for motor 1
gpio.setup(22, gpio.OUT) #GPIO22 = Step for motor 1

if motor==0:
    #Set direction of rotation
    if direction == 'left':
        gpio.output(27, True)
    elif direction == 'right':
        gpio.output(27, False)
     
    StepCounter = 0
     
    #waittime controls speed
    WaitTime = 0.005
     
     
    #Let the magic happen

    # Start main loop
    while StepCounter < steps:
     
        #turning the gpio on and off tells the easy driver to take one step
        gpio.output(22, True)
        gpio.output(22, False)
        StepCounter += 1
        time.sleep(WaitTime)

elif motor==1:
    #Set direction of rotation
    if direction == 'left':
        gpio.output(23, True)
    elif direction == 'right':
        gpio.output(23, False)
     
    StepCounter = 0
     
    #waittime controls speed
    WaitTime = 0.005
     
     
    #Let the magic happen

    # Start main loop
    while StepCounter < steps:
     
        #turning the gpio on and off tells the easy driver to take one step
        gpio.output(24, True)
        gpio.output(24, False)
        StepCounter += 1
        time.sleep(WaitTime)
 
#relase the GPIO
gpio.cleanup()

I also used the pictures there to guide my wiring plus the step down resistors previously mentioned.

Any suggestions on what I should do to isolate these signals so I can get control of just one motor at a time would be most appreciated. Thanks,

-sloslo

Hello, sloslo.

I looked at your code and did not notice anything obviously wrong. Can you post pictures showing how you have everything connected in your setup?

- Amanda