Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5120

Python • Re: Struggling with GPIOZero for Motor Control Using TB6600 Microstep Driver

$
0
0
Perhaps I may be misunderstanding your code, but I don't see where the code changes the state of the direction pin.

I see

Code:

direction = OutputDevice(dir_pin, active_high=True)  # Active high to rotate CW
But in set_direction, I don't see anything that affects the output device.

If you change the code snippet above to

Code:

direction = OutputDevice(dir_pin, active_high=False)  # Active low to rotate CCW
The motor will most likely go in the reverse direction.
I have tried that too but apparently it doesn't work. I switched back to raspi 4 because raspi 5 doesn't have a lib where it will use the dir as intended like in RPi.GPIO lib

Code:

def spin_motor(direction_pin, pulse_pin, enable_pin, direction, steps):    GPIO.output(enable_pin, GPIO.LOW)  # Enable motor    GPIO.output(direction_pin, cw_direction_1 if direction == "CW" else ccw_direction_1)    for _ in range(steps):        GPIO.output(pulse_pin, GPIO.HIGH)        sleep(0.0001)        GPIO.output(pulse_pin, GPIO.LOW)        sleep(0.0005)    GPIO.output(enable_pin, GPIO.LOW)  # Disable motor after spin

Statistics: Posted by XGTFrostKing — Sat Dec 14, 2024 7:24 pm



Viewing all articles
Browse latest Browse all 5120

Trending Articles