我正在尝试使用 cytron 4 通道电机驱动器在我的树莓派上运行 4 个电机。
我的代码适用于反向和左/右转,但我不能同时将所有 GPIO 引脚设置为高电平。
部分代码:
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
MOTOR1Direction = 11
MOTOR1Enable = 13
etc for other 3 motors
GPIO.setup(MOTOR1Direction,GPIO.OUT)
GPIO.setup(MOTOR1Enable,GPIO.OUT)
etc for the other 3 motors
p1 = GPIO.PWM(MOTOR1Enable, 100)
etc for the other 3 motors
def forward(pwmVal):
GPIO.output(MOTOR1Direction, GPIO.HIGH)
GPIO.output(MOTOR2Direction, GPIO.HIGH)
GPIO.output(MOTOR3Direction, GPIO.HIGH)
GPIO.output(MOTOR4Direction, GPIO.HIGH)
p1.start(pwmVal)
p2.start(pwmVal)
p3.start(pwmVal)
p4.start(pwmVal)
def reverse(pwmVal):
GPIO.output(MOTOR1Direction, GPIO.LOW)
GPIO.output(MOTOR2Direction, GPIO.LOW)
GPIO.output(MOTOR3Direction, GPIO.LOW)
GPIO.output(MOTOR4Direction, GPIO.LOW)
p1.start(pwmVal)
p2.start(pwmVal)
p3.start(pwmVal)
p4.start(pwmVal)
def left(pwmVal):
GPIO.output(MOTOR1Direction, GPIO.HIGH)
GPIO.output(MOTOR2Direction, GPIO.HIGH)
GPIO.output(MOTOR3Direction, GPIO.LOW)
GPIO.output(MOTOR4Direction, GPIO.LOW)
p1.start(pwmVal)
p2.start(pwmVal)
p3.start(pwmVal)
p4.start(pwmVal)
因此,当我运行 reverse(100) 时,它可以工作,左/右相同,但是当我运行 forward(100) 时,什么也没有发生。如果我将转发代码中的任何一个 HIGH 更改为 LOW 是否有效?