stepper motor not turning clockwise

41 Views Asked by At

i have to let my stepper motor turn clockwise or anticlockwise with a push of a button with the esp32. i just need to know how to let it turn clockwise, i manage to do it anticlockwise but i can't find it to let it go clockwise. this is my code to let it turn clockwise:

from machine import Pin
from time import sleep, ticks_ms

stepper_pins = [19,21,22,23]

stepper_pin_objects = []

for pin in stepper_pins:
    stepper_pin_obj = Pin(pin, Pin.OUT)
    stepper_pin_objects.append(stepper_pin_obj)
    
while True:
    
    for step in range(512):
        
        for x in range(4):
            #new magnet on
            stepper_pin_objects[x].value(0)
            # previoues magnet off
            y = x + 1
            if y == 4:
                y = 0
            stepper_pin_objects[y].value(1)   

            sleep(0.002) 

            
    sleep(1)

but it still goes the opposite way

1

There are 1 best solutions below

0
denis On

oke i found it :)

    for step in range(511):

    
    for x in reversed(range(4)):

        #nieuwe magneet aan
        stepper_pin_objects[x].value(1)
        # vorige magneet uit
        y = x+1
        if y > 3 :
            y = 0
        stepper_pin_objects[y].value(0)   

        sleep(0.002)    # 0.002 sec is minimum     

        
sleep(1)