On Wed, 2 May 2018 21:51:08 -0700 (PDT), Mala Dies
<
fun...@gmail.com> declaimed the following:
>import Adafruit_BBIO.GPIO as GPIO
>import time
>
>GPIO.setup("P9_21", GPIO.OUT)
>GPIO.setup("P9_22", GPIO.OUT)
>GPIO.setup("P9_12", GPIO.OUT)
>GPIO.setup("P9_15", GPIO.OUT)
>
>m1a = GPIO.output("P9_21", GPIO.HIGH)
>m1a = GPIO.output("P9_22", GPIO.HIGH)
Meaningless assignments... First, the return from the second line
replaces the value returned by the first line, since you used the same name
for the return.
On the other hand -- based upon the documentation for the library,
GPIO.output() doesn't return anything so you are just replacing None with
None.
>m1b = GPIO.output("P9_12", GPIO.HIGH)
>m1b = GPIO.output("P9_15", GPIO.HIGH)
>
Ditto
You've set all control pins high -- which should, for any motor
controller I can envision, mean the motors are not powered (BTW -- you did
wire the ENABLE A and B pins to something, didn't you?
>while (True):
>
> try:
> for motor in range (0, 101, 1): #starts at 0, steps up to
>101 in 1 steps
> m1a = ("P9_21")
Here you assign a string to the name, but you never do anything with
the string. So... again a meaningless assignment.
> time.sleep(3)
> print(motor)
And you never do anything with the motor pin itself, so nothing
changes.
This loop condenses down to just printing integers from 0..100 with a 3
second pause between them, and it does all of them before moving to the
next loop, which does the very same thing.
> for motor in range (0, 101, 1):
> m1a = ("P9_22")
> time.sleep(3)
> print(motor)
> for motor in range (100, -1, -1):
> m1b = ("P9_12")
> time.sleep(3)
> print(motor)
> for motor in range (100, -1, -1):
> m1b = ("P9_15")
> time.sleep(3)
> print(motor)
>
What behavior are you expecting since the above four loops are coded to
run on after the other -- nothing is being done in parallel even if you
were changing motor pin settings.
> except(KeyboardInterrupt):
>
> #And final cleanup
> print "You have just ended your camp trip!"
> GPIO.cleanup()
> quit()
Your "final cleanup" will only be performed IF you hit <ctrl-c> BEFORE
the loops run out. Otherwise, you just fall off the end of the program with
no cleanup performed
My suggestion -- since you are using Python...
Open a shell and run Python in interactive mode, and then enter GPIO
statements one at a time setting pins to HIGH and LOW, in various
combinations, to see what it takes to activate the motors.
And, just for a giggle (untested as I don't have your hardware present)
-=-=-=-=-
"""
Pseudo-code for fictitious robot-car with two driving wheels, using
brushed DC motors; I do not have the driver board or motors so this
is just text of what I believe would be needed
NOTE: THIS IS PYTHON 2.7 SYNTAX; modify as needed for 3.x
"""
import time
import Adafruit_BBIO.GPIO as GPIO
class BrushedDC(object):
def __init__(self, p1, p2):
self.p1 = p1
self.p2 = p2
GPIO.setup(self.p1, GPIO.OUT)
GPIO.setup(self.p2, GPIO.OUT)
self.stop()
def stop(self):
GPIO.output(self.p1, GPIO.LOW)
GPIO.output(self.p2, GPIO.LOW)
def forward(self):
self.stop() #safety to avoid shock of reversals
GPIO.output(self.p1, GPIO.HIGH)
GPIO.output(self.p2, GPIO.LOW)
def reverse(self):
self.stop()
GPIO.output(self.p1, GPIO.LOW)
GPIO.output(self.p2, GPIO.HIGH)
class Car(object):
def __init__(self, leftMotor, rightMotor):
self.leftMotor = leftMotor
self.rightMotor = rightMotor
self.stop()
def stop(self, wait=0):
self.leftMotor.stop()
self.rightMotor.stop()
time.sleep(wait)
def forward(self, wait=0):
self.leftMotor.forward()
self.rightMotor.forward()
time.sleep(wait)
def reverse(self, wait=0):
self.leftMotor.reverse()
self.rightMotor.reverse()
time.sleep(wait)
def leftTurnForward(self, wait=0):
self.leftMotor.stop()
self.rightMotor.forward()
time.sleep(wait)
def rightTurnForward(self, wait=0):
self.leftMotor.forward()
self.rightMotor.stop()
time.sleep(wait)
def leftTurnReverse(self, wait=0):
self.leftMotor.stop()
self.rightMotor.reverse()
time.sleep(wait)
def rightTurnReverse(self, wait=0):
self.leftMotor.reverse()
self.rightMotor.stop()
time.sleep(wait)
def leftPivot(self, wait=0):
self.leftMotor.reverse()
self.rightMotor.forward()
time.sleep(wait)
def rightPivot(self, wait=0):
self.leftMotor.forward()
self.rightMotor.reverse()
time.sleep(wait)
myCar = Car(leftMotor=BrushedDC(p1="P9_21", p2="P9_22"),
rightMotor=BrushedDC(p1="P9_12", p2="P9_15"))
myCar.forward(10)
myCar.leftPivot(3)
myCar.forward(5)
myCar.rightTurnReverse(3)
myCar.reverse(10)
myCar.stop(10)
myCar.rightPivot(30)
myCar.forward(5)
myCar.rightTurnForward(15)
myCar.stop()
GPIO.cleanup()
-=-=-=-=-=-
--
Wulfraed Dennis Lee Bieber AF6VN
wlf...@ix.netcom.com HTTP://wlfraed.home.netcom.com/