0

I got a Raspberry Pi 3B, That ive hooked 4 DC motors up to (with a motor controller of course). I run the program and they do not move, i cant figure out if im missing something or wired something up wrong. Does anyone else see it?

Things ive tried:

  • Ive played around with the code by changing the Highs and Lows
  • Ive completely bypassed PWM by wiring the ENA Pin on the motor controller to 5v

Other Info:

  • Im using the L293D motor controller, data sheet HERE
  • Coding in Python 3.5.3
  • I know at least one motor is receiving power because when i run gpio.cleanup() it will then start moving, but no other time

WIRING: Well its a rats nest, but ive got (only talking about one motor controller, and using BCM numbering)

  • 1,2EN on gpio 2
  • 3,4EN on gpio 18
  • Vcc1 to Pi 5v
  • Vcc2 to 4*AA Positive
  • 1A to gpio 3
  • 2A to gpio 4
  • 3A to gpio 24
  • 4A to gpio23
  • 1Y to Motor 1 Positive
  • 2Y to motor 1 Negative
  • 3Y to motor 2 Negative
  • 4Y to motor 2 positive
  • And all MC grounds to Pi ground
  • Battery ground to Pi ground as well

CODE: **Idk why the code doesnt stay together

Rover Class (at least whats relevent)

import RPi.GPIO as gpio
import time

class RoverMovement:
##################Set forward and backs as needed to comments on motors
    RF1 = 3     #Right Front
    RF2 = 4     #Right Front
    RFPWMPin = 2   #Right Front PWM
    LF1 = 12     #Left Front
    LF2 = 20     #Left Front
    LFPWMPin = 26   #Left Front PWM
    RR1 = 23     #Right Rear
    RR2 = 24     #Right Rear
    RRPWMPin = 18   #Right Rear PWM
    LR1 = 13     #Left Rear
    LR2 = 19     #Left Rear
    LRPWMPin = 21   #Left Rear PWM

    def __init__(self):#Runs when class is created
        gpio.setwarnings(False)
        gpio.setmode(gpio.BCM)

        #Motor Pins Setup
        gpio.setup(RoverMovement.RF1,gpio.OUT) # Gpio Function takes in (Channel, Output or Input)
        gpio.setup(RoverMovement.RF2,gpio.OUT)
        gpio.setup(RoverMovement.LF1,gpio.OUT)
        gpio.setup(RoverMovement.LF2,gpio.OUT)
        gpio.setup(RoverMovement.RR1,gpio.OUT)
        gpio.setup(RoverMovement.RR2,gpio.OUT)
        gpio.setup(RoverMovement.LR1,gpio.OUT)
        gpio.setup(RoverMovement.LR2,gpio.OUT)
        gpio.setup(RoverMovement.RFPWMPin,gpio.OUT) #Setup PWM Pins to Output
        gpio.setup(RoverMovement.LFPWMPin,gpio.OUT)
        gpio.setup(RoverMovement.RRPWMPin,gpio.OUT)
        gpio.setup(RoverMovement.LRPWMPin,gpio.OUT)
##        RFSpeed = gpio.PWM(RoverMovement.RFPWMPin,1000) # Pwm Function takes in (Channel,Frequency)
##        LFSpeed = gpio.PWM(RoverMovement.LFPWMPin,1000)
##        RRSpeed = gpio.PWM(RoverMovement.RRPWMPin,1000)
##        LRSpeed = gpio.PWM(RoverMovement.LRPWMPin,1000)


        #Initialize To Low / and duty cycles (0-100)
        gpio.output(RoverMovement.RF1,gpio.LOW)
##        RFSpeed.start(0)
##        LFSpeed.start(0)
##        RRSpeed.start(0)
##        LRSpeed.start(0)
        print("Movement Initialized")

    #Movement Functions
    def MoveForward(self,speed,timer):
        print("Moving Forward at {}% speed for {} seconds".format(speed,timer))

        #Create Speed Objects
        RFSpeed = gpio.PWM(RoverMovement.RFPWMPin,1000) # Pwm Function takes in (Channel,Frequency)
        LFSpeed = gpio.PWM(RoverMovement.LFPWMPin,1000)
        RRSpeed = gpio.PWM(RoverMovement.RRPWMPin,1000)
        LRSpeed = gpio.PWM(RoverMovement.LRPWMPin,1000)

        #Set Speeds
        RFSpeed.ChangeDutyCycle(speed)
        LFSpeed.ChangeDutyCycle(speed)
        RRSpeed.ChangeDutyCycle(speed)
        LRSpeed.ChangeDutyCycle(speed)

        #Moving
        gpio.output(RoverMovement.RF1,gpio.HIGH)
        gpio.output(RoverMovement.LF1,gpio.HIGH)
        gpio.output(RoverMovement.RR1,gpio.HIGH)
        gpio.output(RoverMovement.LR1,gpio.HIGH)

        time.sleep(timer) #Timer

        #Stop Motors
        gpio.output(RoverMovement.RF1,gpio.LOW)
        gpio.output(RoverMovement.LF1,gpio.LOW)
        gpio.output(RoverMovement.RR1,gpio.LOW)
        gpio.output(RoverMovement.LR1,gpio.LOW)

The code running it:

import time
import RoverClasses
import RPi.GPIO as gpio

RMove = RoverClasses.RoverMovement()
RLED = RoverClasses.RoverLED()
RBuzzer = RoverClasses.RoverBuzzer()

try:
    #Program On Beep
    RBuzzer.BeepBuzzer(1.5)

    #LED Test
    RLED.BlinkOneLED(RLED.LED1,.2)
    time.sleep(.2)
    RLED.BlinkOneLED(RLED.LED2,.2)
    time.sleep(.2)
    RLED.BlinkTwoLEDs(RLED.LED1,RLED.LED2,.2)
    time.sleep(.2)
    RLED.TurnOnLED(RLED.LED1)
    time.sleep(.2)
    RLED.TurnOffLED(RLED.LED1)
    time.sleep(.2)
    RLED.TurnOnLED(RLED.LED2)
    time.sleep(.2)
    RLED.TurnOffLED(RLED.LED2)
    time.sleep(.2)

    #Motor Test
    RMove.MoveForward(100,1.5)

    #Buzzer Test / Program Done Beep
    RBuzzer.TurnOnBuzzer()
    time.sleep(.5)
    RBuzzer.TurnOffBuzzer()

except KeyboardInterrupt:
    RLED.TurnOffLED(RLED.LED1)  #Turn of the LEDs
    RLED.TurnOffLED(RLED.LED2)
    RBuzzer.TurnOffBuzzer()
    print("Rover Stopped")

finally:
    print('Rover Now Idle...')
    gpio.cleanup() #Clean up the GPIO after the program has finished
  • 4
    Start from scratch. Connect one motor. Use one simple script. – joan Nov 21 '18 at 21:23
  • I don't know much about this, but given the specs & what you mention about your wiring, I'd expect you to drive gpio 2 & 18 high/low to start/stop your motors, and PWM signals on gpio 3, 4, 24 & 23. Your code drives PWM signals on gpio 2, 26, 18 & 21. – SleuthEye Nov 24 '18 at 14:39

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.