[Python] Control DC motors in python

Discussão em 'Python' iniciado por Stack, Julho 2, 2025.

  1. Stack

    Stack Membro Participativo

    I control two DC motors with BTS driver using raspberry. In one file I have this:

    def backwardFullSpeedBTS():
    rSpeed.ChangeDutyCycle(10)
    lSpeed.ChangeDutyCycle(0)

    def forwardFullSpeedBTS():
    rSpeed.ChangeDutyCycle(0)
    lSpeed.ChangeDutyCycle(10)

    def stopBTSMotor():
    rSpeed.ChangeDutyCycle(0)
    lSpeed.ChangeDutyCycle(0)

    def start2ndMotor():
    rSpeed2.ChangeDutyCycle(80)
    lSpeed2.ChangeDutyCycle(0)

    def stop2ndMotor():
    rSpeed2.ChangeDutyCycle(0)
    lSpeed2.ChangeDutyCycle(0)


    In the next file I call the previous functions:

    from MotorBTS import *

    while GPIO.input(gpio_ButtonMStop) != 0:
    """Move arm outward until stop button pressed"""
    forwardFullSpeedBTS()
    pass
    stopBTSMotor() # stops Motor

    cTime = float(time.time())
    while checkDelay(cTime, 0.5):
    start2ndMotor()
    pass
    stop2ndMotor()


    Only it always calls me only the first engine and start2ndMotor never. The problem is that it only imports the first engine, but not the second. I tried splitting the engines into their own files, but it still didn't call the second engine. Do you have any other way to call it or how to solve it?

    Continue reading...

Compartilhe esta Página