1

Two Motors without PWM This picture shows the code i am using to run back and forth a dc motor for specified time and it works well, no problem with this.!

Problem is here, as soon as i switch on my Pi and try to run the pwm code motor doesnt run, but when i run the code in 1st picture and then run the pwm code it runs fine... whats happening here??? Am i missing something?? Did i not activate some Pin or something like that??
pwm code

import RPi.GPIO as GPIO ## Import GPIO library
import time ## Import 'time' library. Allows us to use 'sleep'

GPIO.setmode(GPIO.BOARD) ## Use board pin numbering
GPIO.setup(11, GPIO.OUT) ## Setup GPIO Pin 11(motor b enable) to OUT
GPIO.setup(7, GPIO.OUT)  ## Setup GPIO Pin 11(motor a enable) to OUT
GPIO.setup(13, GPIO.OUT) ## Setup GPIO Pin 11(motor a control) to OUT
GPIO.setup(15, GPIO.OUT)  ## Setup GPIO Pin 11(motor a control) to OUT
GPIO.setup(16, GPIO.OUT)   ## Setup GPIO Pin 11(motor b control) to OUT
GPIO.setup(18, GPIO.OUT)    ## Setup GPIO Pin 11(motor b control) to OUT
GPIO.output(7, False)        ## disable motor a
GPIO.output(11, True)          ## enable motor b
p=GPIO.PWM(11,50)          ## frequency 50
p.start(1)
try:
    while True:
           GPIO.output(13, False)   ## dont run motor a
           GPIO.output(15, False)      ## dont run motor a
           GPIO.output(16, True)        ##  run motor b
           GPIO.output(18, False)         ##  run motor b
           p.ChangeDutyCycle(10)     ## duty cycle 10%
except KeyboardInterrupt:
     pass
p.stop()
gpio.cleanup()
2

I think GPIO.setup(18, False) should be GPIO.output(18, False)

PS 10% duty cycle might not be enough to set the motor into motion.

  • sorry i entered a mistake, i corrected it now...but why is it running(at 10%) after running first code.....its not working only if try to run the code before running the first – Ruthvik Vaila Feb 10 '14 at 13:40
  • @RuthvikVaila Why not see if 90% works? 10% may be enough to keep the motor running once started but not enough to run from a cold start, – joan Nov 28 '14 at 22:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.