Question Will my code still apply with to my Nema 17/23 motor set up with tb6600?

Oct 20, 2023
3
0
10
So I saw a post regarding this the OP mentioned he wants to make a gantry system. I'd like to make a similar x-y axis moving machine. Saw on the comments to connect these up using a schematic putting some transistors and resistors on the negative (-) en pulse and dir pins while the + pins of these are on 5V pin on RPi. I cant seem to insert an image. Tried to do the schematic and the code below:


Python:
import RPi.GPIO as GPIO
import time

# Define GPIO pins for Step, Direction, and Enable
STEP_PIN = 17
DIR_PIN = 22
ENABLE_PIN = 27  # Use BCM pin 27 for the Enable pin

# Set GPIO mode and pins
GPIO.setmode(GPIO.BCM)
GPIO.setup(STEP_PIN, GPIO.OUT)
GPIO.setup(DIR_PIN, GPIO.OUT)
GPIO.setup(ENABLE_PIN, GPIO.OUT)

# Function to control motor movement
def move_motor(steps, delay):
    # Set direction (True for clockwise, False for counterclockwise)
    GPIO.output(DIR_PIN, True)  # Change to False if you want to move counterclockwise

    # Enable the motor driver
    GPIO.output(ENABLE_PIN, True)

    # Generate step pulses to move the motor
    for _ in range(steps):
        GPIO.output(STEP_PIN, GPIO.HIGH)
        time.sleep(delay)
        GPIO.output(STEP_PIN, GPIO.LOW)
        time.sleep(delay)

    # Disable the motor driver
    GPIO.output(ENABLE_PIN, False)

# Example usage: Move the motor 200 steps with a delay of 0.005 seconds between steps
move_motor(200, 0.005)

# Cleanup GPIO pins
GPIO.cleanup()

but it wont work. Tried to just directly put it into my driver and the GPIO pins, it works but seems to be having some noise and wringing sounds

Any help on this is greatly appreciated