title: Raspberry pi Running Two Motors
body: <p>I'm using two DC motors one with L298N and 2nd motor with BTS driver on raspberry pi.
  I have created a separate file and created separated functions to start and stop individual motors. I have tested the function by calling them individually and also together to run both motors.
  Now here's the problem. I'm calling function of L298N motor driver in my main file. But it's not working.
  Here's my code of motors
  
  import RPi.GPIO as GPIO<br/></p>
  <p>GPIO.setwarnings(False)<br/>
  from time import sleep<br/></p>
  <h1>import the library</h1>
  <p>from RpiMotorLib import rpiservolib<br/></p>
  <p>myservotest = rpiservolib.SG90servo(&quot;servoone&quot;, 50, 2, 12)<br/></p>
  <p>rPwm = 24<br/>
  lPwm = 23<br/>
  rEn = 25<br/>
  lEn = 22<br/></p>
  <h1>These pins are for new BTS instead of L298N Driver</h1>
  <p>rPwm2 = 6<br/>
  lPwm2 = 5<br/>
  rEn2 = 16<br/>
  lEn2 = 12<br/></p>
  <h1>For main DC motor to Move Arm</h1>
  <p>GPIO.setmode(GPIO.BCM)<br/>
  GPIO.setup(rPwm, GPIO.OUT)<br/>
  GPIO.setup(lPwm, GPIO.OUT)<br/>
  GPIO.setup(rPwm2, GPIO.OUT)<br/>
  GPIO.setup(lPwm2, GPIO.OUT)<br/></p>
  <p>GPIO.setup(rEn, GPIO.OUT)<br/>
  GPIO.setup(lEn, GPIO.OUT)<br/>
  GPIO.setup(rEn2, GPIO.OUT)<br/>
  GPIO.setup(lEn2, GPIO.OUT)<br/></p>
  <p>GPIO.output(rPwm, GPIO.LOW)<br/>
  GPIO.output(lPwm, GPIO.LOW)<br/>
  GPIO.output(rEn, GPIO.HIGH)<br/>
  GPIO.output(lEn, GPIO.HIGH)<br/>
  <br/>
  GPIO.output(rPwm2, GPIO.LOW)<br/>
  GPIO.output(lPwm2, GPIO.LOW)<br/>
  GPIO.output(rEn2, GPIO.HIGH)<br/>
  GPIO.output(lEn2, GPIO.HIGH)<br/></p>
  <p>rSpeed = GPIO.PWM(rPwm, 1000)<br/>
  rSpeed2 = GPIO.PWM(rPwm2, 1000)<br/>
  lSpeed = GPIO.PWM(lPwm, 1000)<br/>
  lSpeed2 = GPIO.PWM(lPwm2, 1000)<br/>
  rSpeed.start(100)<br/>
  lSpeed.start(100)<br/></p>
  <h1>For 2nd DC Motor</h1>
  <p>GPIO.setup(rPwm2, GPIO.OUT)<br/>
  GPIO.setup(lPwm2, GPIO.OUT)<br/>
  GPIO.setup(rEn2, GPIO.OUT)<br/>
  GPIO.setup(lEn2, GPIO.OUT)<br/>
  <br/>
  GPIO.output(rPwm2, GPIO.LOW)<br/>
  GPIO.output(lPwm2, GPIO.LOW)<br/>
  GPIO.output(rEn2, GPIO.HIGH)<br/>
  GPIO.output(lEn2, GPIO.HIGH)<br/></p>
  <p>rSpeed2.start(100)<br/>
  lSpeed2.start(100)<br/></p>
  <p>def backwardFullSpeedBTS():<br/>
  '''This function will move BTS Motor at full speed in Forward Direction''' <br/>
  rSpeed.ChangeDutyCycle(10) <br/>
  lSpeed.ChangeDutyCycle(0) <br/>
  # GPIO.output(rPwm,GPIO.HIGH)<br/>
  # GPIO.output(lPwm,GPIO.LOW)<br/></p>
  <p>def forwardFullSpeedBTS():<br/>
  '''This function will move BTS Motor at full speed in Backward Direction'''<br/>
  rSpeed.ChangeDutyCycle(0)<br/>
  lSpeed.ChangeDutyCycle(10)<br/>
  # GPIO.output(rPwm,GPIO.LOW)<br/>
  # GPIO.output(lPwm,GPIO.HIGH)<br/></p>
  <p>def stopBTSMotor():<br/>
  '''This function will stop BTS Motor'''<br/>
  #     GPIO.output(rPwm,GPIO.LOW)<br/>
  #     GPIO.output(lPwm,GPIO.LOW)<br/>
  rSpeed.ChangeDutyCycle(0)<br/>
  lSpeed.ChangeDutyCycle(0)<br/></p>
  <p>def backwardAtSpeedBTS(speed):<br/>
  '''This function will move BTS Motor at full speed in Forward Direction'''<br/>
  rSpeed.ChangeDutyCycle(speed)<br/>
  lSpeed.ChangeDutyCycle(0)<br/>
  # GPIO.output(rPwm,GPIO.HIGH)<br/>
  # GPIO.output(lPwm,GPIO.LOW)<br/></p>
  <p>def forwardAtSpeedBTS(speed):<br/>
  '''This function will move BTS Motor at full speed in Backward Direction'''<br/>
  rSpeed.ChangeDutyCycle(0)<br/>
  lSpeed.ChangeDutyCycle(speed)<br/>
  # GPIO.output(rPwm,GPIO.LOW)<br/>
  # GPIO.output(lPwm,GPIO.HIGH)<br/></p>
  <br/>
  def start2ndMotor():<br/>
      '''This function will move 2nd BTS Motor at full speed in Forward Direction'''<br/>
      rSpeed2.ChangeDutyCycle(80)<br/>
      lSpeed2.ChangeDutyCycle(0)<br/>
  <br/>
  <p>def stop2ndMotor():<br/>
  # Stop 2nd DC motor connected at BTS<br/>
  rSpeed2.ChangeDutyCycle(0)<br/>
  lSpeed2.ChangeDutyCycle(0)<br/></p>
  <br/>
  def closeServo():<br/>
      '''This function will close the arm to pick a puck'''<br/>
      # Move servo from 120 to 60<br/>
      myservotest.servo_move(7, 11, 1, False, 1)<br/>
  <p>def openServo():<br/>
  # Move servo from 90 to 120<br/>
  myservotest.servo_move(7, 7, 1, True, 1)<br/>
  &lt;\code&gt;</p>
   This is how I'm importing the functions  <br/>
  **from motorFunction import * **
  
  from MotorBTS import * <br/>
  def onStart():<br/>
      global motorPosition<br/>
      print("On Start")<br/>
      root.update()<br/>
      closeServo()<br/>
      while GPIO.input(gpio_ButtonMStop) != 0:<br/>
          """Move arm outward until stop button pressed"""<br/>
          forwardAtSpeedBTS(20)<br/>
          pass<br/>
      # After stop button pressed stop moving DC Motor<br/>
      stopBTSMotor()  # stops Motor<br/>
      cTime = float(time.time())<br/>
      ***start2ndMotor()***<br/>
      while checkDelay(cTime, 0.5):<br/>
                  # Wait for 0.5 second<br/>
          pass<br/>
      stop2ndMotor()<br/>
      while GPIO.input(gpio_ButtonPuckMotor) != 0:<br/>
          """Move puck motor at zero Position"""<br/>
          motorPuck.motor_go(False,  # True=Clockwise, False=Counter-Clockwise<br/>
                             "Full",  # Step type (Full,Half,1/4,1/8,1/16,1/32)<br/>
                             100,  # number of steps<br/>
                             .0005,  # step delay [sec]<br/>
                             False,  # True = print verbose output<br/>
                             .05)  # initial delay [sec]<br/>
      print("Done")<br/>
  
  When i call **start2ndMotor()** In the startup it doesn't run the motor only the first motor that was called **forwardAtSpeedBTS(20)** works.