无法将所有GPIO引脚置于高4通道马达con

2024-10-05 21:58:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着运行4个电机与我的树莓圆周率使用cytron 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)

所以当我倒着跑(100)的时候,它起作用了,左/右都一样,但是当我向前跑(100)的时候,什么也没发生。如果我把转发代码中的任何一个高的改成低的,它能工作吗


Tags: 代码foroutputgpiodefetcstartlow