Cannot put all GPIO pins to high 4 channel motor controller

62 Views Asked by At

I'm trying to run 4 motors with my raspberry pi using a cytron 4 channel motor driver.

My code works for reverse and for left/right turns but I cannot put all GPIO pins to high at the same time.

parts of the code:

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)

So when I run reverse(100) it works, same for left/right, but when I run forward(100) nothing happens. If I change any one of the HIGH's in the forward code to LOW it works?

0

There are 0 best solutions below