Cant get Stepper Motor to move with RPi 4b

July 11, 2024, 03:51

h_0_p

Hey all, I have a crazy project I am working on. I have a raspberry pi that needs to operate a NEMA17 stepper motor. I have an A4988 motor driver. I know this "section" of my project isn't necessarily RPi related, but I am building up to it.. just need to get over this hump, before asking any RPi questions 😄 Using the formula: Vref=Current Limit2.5×Sense Resistor ValueVref=2.5×Sense Resistor ValueCurrent Limit​ According to the formula (see attached image) the Vref should be 1.2V I have 12V applied to the driver, but not getting a reading on the multimeter when turning the screw. I put the positive probe on the screw, negative on the ground pin on the driver, and get no reading. any ideas?

h_0_p

very possible it isn't the driver.. I can't seem to get the motor to move

h_0_p

python
Raspberry Pi GPIO    A4988/DRV8825 Pins    Stepper Motor Coils    External Power Supply
------------------    ------------------    ------------------    ---------------------
3.3V (Pin 1)         -> VDD
GND (Pin 6)          -> GND
GPIO 17 (Pin 11)     -> STEP
GPIO 27 (Pin 13)     -> DIR
GND (Pin 6)          -> EN
VMOT                 -> VMOT               -> Red (1A)
GND                  -> GND                -> Blue (1B)
                                           -> Black (2A)
                                           -> Green (2B)
I triple checked my connections.
import RPi.GPIO as GPIO
import time
 
# GPIO setup
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
 
# Stepper Motor GPIO pins
STEP_PIN = 17
DIR_PIN = 27
GPIO.setup(STEP_PIN, GPIO.OUT)
GPIO.setup(DIR_PIN, GPIO.OUT)
 
# Function to control stepper motor
def move_stepper_motor_continuous(step_pin, dir_pin, delay):
    GPIO.output(dir_pin, GPIO.LOW)  # Set direction to counter-clockwise
    while True:
        GPIO.output(step_pin, GPIO.HIGH)
        time.sleep(delay)
        GPIO.output(step_pin, GPIO.LOW)
        time.sleep(delay)
 
# Main function
if __name__ == "__main__":
    try:
        # Medium speed: adjust delay as needed
        delay = 0.005
        move_stepper_motor_continuous(STEP_PIN, DIR_PIN, delay)
    except KeyboardInterrupt:
        # Cleanup GPIO settings on exit
        GPIO.cleanup()

oops.se

Your text doesn't make sense without a schema.

h_0_p

The text above describes how the wires are connected

h_0_p

tried a different wiring, and script.
Components

    Raspberry Pi (3.3V logic)
    A4988 Stepper Motor Driver
    NEMA 17 Stepper Motor
    12v External Power Supply

Connections
A4988 Driver to Raspberry Pi:

    VDD -> Raspberry Pi 3.3V (Pin 1)
    GND -> Raspberry Pi GND (Pin 6)
    STEP -> Raspberry Pi GPIO 17 (Pin 11)
    DIR -> Raspberry Pi GPIO 27 (Pin 13)
    EN -> Raspberry Pi GND (Pin 6)

A4988 Driver to Stepper Motor:

    1A -> Red (Pin 1 on the motor)
    1B -> Blue (Pin 4 on the motor)
    2A -> Black (Pin 3 on the motor)
    2B -> Green (Pin 6 on the motor)

A4988 Driver to External Power Supply:

    VMOT -> Positive terminal of the external power supply 
    GND -> Negative terminal of the external power supply

python
import RPi.GPIO as GPIO
from RpiMotorLib import RpiMotorLib
import time
import sys

# Redirect stdout to a file
log_file = '/home/halloween_clock/motor_control.log'
sys.stdout = open(log_file, 'w')

try:
    ################################
    # RPi and Motor Pre-allocations
    ################################
    #
    # Define GPIO pins
    direction = 22  # Direction (DIR) GPIO Pin
    step = 23       # Step GPIO Pin
    EN_pin = 24     # Enable pin (LOW to enable)

    # Declare an instance of class pass GPIO pins numbers and the motor type
    mymotortest = RpiMotorLib.A4988Nema(direction, step, (21, 21, 21), "A4988")
    GPIO.setup(EN_pin, GPIO.OUT)  # Set enable pin as output

    ###########################
    # Actual motor control
    ###########################
    #
    GPIO.output(EN_pin, GPIO.LOW)  # Pull enable to low to enable motor
    mymotortest.motor_go(False,  # True=Clockwise, False=Counter-Clockwise
                         "Full",  # Step type (Full,Half,1/4,1/8,1/16)
                         200,  # Number of steps
                         0.0005,  # Step delay [sec]
                         True,  # True = print verbose output 
                         0.05)  # Initial delay [sec]

except Exception as e:
    print(f"An error occurred: {e}")

finally:
    GPIO.cleanup()  # Clear GPIO allocations after run
    sys.stdout.close()

h_0_p

Still can't get the motor to move. I verified VRef on the driver, tried a different driver and motor, same result

h_0_p

Solved it.