Hardware Reference
In-Depth Information
3. We test both the motors by rotaing them in both direcions for 10 seconds and
stopping them:
while True:
#Rotate both motors forward for 10 seconds
GPIO.output(8,GPIO.HIGH)
GPIO.output(9,GPIO.LOW)
GPIO.output(10,GPIO.HIGH)
GPIO.output(11,GPIO.LOW)
sleep(10)
#Stop motors and rotate in reverse directions
GPIO.output(8,GPIO.LOW)
GPIO.output(10,GPIO.LOW)
#Go reverse
GPIO.output(9,GPIO.HIGH)
GPIO.output(11,GPIO.HIGH)
sleep(10)
#Stop motors and rotate both in opposite directions
GPIO.output(9,GPIO.LOW)
GPIO.output(11,GPIO.LOW)
GPIO.output(8,GPIO.HIGH)
GPIO.output(9,GPIO.LOW)
GPIO.output(10,GPIO.LOW)
GPIO.output(11,GPIO.HIGH)
sleep(10)
#Stop Motors
GPIO.output(8,GPIO.LOW)
GPIO.output(9,GPIO.LOW)
GPIO.output(10,GPIO.LOW)
GPIO.output(11,GPIO.LOW)
4. In the preceding example, both the motors were running at 100 percent duty
cycle. We will look into controlling the motors using pulse width modulaion.
We will set the pins as output and declare the operaing channel frequencies
for the PWM pins (1kHz):
GPIO.setup(8,GPIO.OUT) #connected to 1A
GPIO.setup(9,GPIO.OUT) #connected to 2A
GPIO.setup(10,GPIO.OUT) #connected to 3A
GPIO.setup(11,GPIO.OUT) #connected to 4A
GPIO.output(9,GPIO.HIGH)
 
Search WWH ::




Custom Search