Управление шаговым двигателем Raspberry Pi 28-BYJ-48 с uln2003 - PullRequest
1 голос
/ 12 июля 2020

Я сейчас пытаюсь управлять шаговым двигателем 28-BYJ-48 с драйвером uln2003. Когда я запускаю свой код, мотор гудит и не двигается. В прилагаемом коде я использую pygame для получения ввода от контроллера и, в конечном итоге, поворота двигателя. Я смог повернуть двигатель с помощью демонстрационного кода, но с новым кодом двигатель просто гудит и меняет высоту звука при изменении направления. (получение входных данных не является проблемой, я тестировал это несколько раз)

Ниже приведен код:

control_pins = [7, 8, 11, 9]
for pin in control_pins:
        GPIO.setup(pin, GPIO.OUT)
        GPIO.output(pin, 0)

halfstep_cw = [
        [1,0,0,0],
        [1,1,0,0],
        [0,1,0,0],
        [0,1,1,0],
        [0,0,1,0],
        [0,0,1,1],
        [0,0,0,1],
        [1,0,0,1]
]

halfstep_ccw = [
        [1,0,0,1],
        [0,0,0,1],
        [0,0,1,1],
        [0,0,1,0],
        [0,1,1,0],
        [0,1,0,0],
        [1,1,0,0],
        [1,0,0,0]
]

control = controller()
#Note, that to use the driver and the controller at all times,
#They must be in a loop
quit = False
while quit == False:
        for event in pygame.event.get():
                if (event.type == pygame.QUIT):
                        quit = True
#This is getting axis 1 to move forward and backward
        move_FB = control.get_value(1)
#This is getting axis 2 to move left and right
        move_LR = control.get_value(2)
#This is getting the value of the buttons, with axis i
        circle = control.get_button_value(13)
        R1 = control.get_button_value(11)
        L1 = control.get_button_value(10)
#For buttons, 1 is pressed, 0 is not pressed
#This will quit the program
        elif circle == 1:
                quit = True
#Move the stepper motor clockwise
        elif R1 == 1:
                 for halfstep in range(8):
                        for pin in range(4):
                                GPIO.output(control_pins[pin], halfstep_cw[halfstep][pin])
#Move the stepper motor counter-clockwise
        elif L1 == 1:
                 for halfstep in range(8):
                        for pin in range(4):
                                GPIO.output(control_pins[pin], halfstep_ccw[halfstep][pin])
        else:
                stop()
GPIO.cleanup()
pygame.QUIT

Любая помощь будет принята с благодарностью.

1 Ответ

1 голос
/ 12 июля 2020

Ответил на свой вопрос. только что добавлен в функцию time.sleep, как показано ниже.

        elif R1 == 1:
                 for halfstep in range(8):
                        for pin in range(4):
                                GPIO.output(control_pins[pin], halfstep_cw[halfstep][pin])
                        time.sleep(0.001)
#Move the stepper motor counter-clockwise
        elif L1 == 1:
                 for halfstep in range(8):
                        for pin in range(4):
                                GPIO.output(control_pins[pin], halfstep_ccw[halfstep][pin])
                        time.sleep(0.001)
...