RE: L298 and Interfacing w/ the BBB/Trying!

150 views
Skip to first unread message

Mala Dies

unread,
Apr 18, 2018, 7:20:20 PM4/18/18
to BeagleBoard
Hello,

I have a L298 Motor Driver. I was wondering a couple of things.

First:

  • Do I need only software to type up to interface w/ motor drivers?
Second:

  • While interfacing w/ this driver, do I need to make a library?

If you have time, please view these ideas if you are willing to relay info. back to me:

Oh and please look over my specific motor driver and the schematic here:


Hopefully...this is enough info. for you to relate to my dilemma. 

Seth

P.S. If you get bored, please do not hesitate to contact me. Thank you to anyone for support. There is a eight pin jumper that I have had some trouble w/ so far. I am not sure where to put the jumper pins.

Mala Dies

unread,
Apr 23, 2018, 10:43:40 PM4/23/18
to BeagleBoard
Hello,

I thought it would be as easy as Uno, Dos, Tres. I was incorrect w/ this option of one, two, three. If you have time and if you are using the Adafruit_BBIO.PWM as PWM library to interface w/ this specific module, let a brother know.

Seth

P.S. I tried a couple of different software examples but I could not even get the motors to show a sign of movement, i.e. even odd movement that would have been uncalled for. Get at me!

Mala Dies

unread,
Apr 24, 2018, 1:07:59 AM4/24/18
to BeagleBoard
Hello Once More,

I am reverting back to 4.4.x. I tried 4.9.x and 4.14.x but to no avail. I will keep plugging at it.

Seth


On Wednesday, April 18, 2018 at 6:20:20 PM UTC-5, Mala Dies wrote:

Mala Dies

unread,
Apr 26, 2018, 4:32:54 PM4/26/18
to BeagleBoard
Hello...

It was a software issue on my side of things. Oops!

Seth

P.S. If you have this board, let me know.


On Wednesday, April 18, 2018 at 6:20:20 PM UTC-5, Mala Dies wrote:

Mala Dies

unread,
May 3, 2018, 12:51:08 AM5/3/18
to BeagleBoard
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)
m1b = GPIO.output("P9_12", GPIO.HIGH)
m1b = GPIO.output("P9_15", GPIO.HIGH)

while (True):

        try:
                for motor in range (0, 101, 1): #starts at 0, steps up to 101 in 1 steps
                    m1a = ("P9_21")
                    time.sleep(3)
                    print(motor)
                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)

        except(KeyboardInterrupt):

                #And final cleanup
                print "You have just ended your camp trip!"
                GPIO.cleanup()
                quit()

Hello,

I am trying to use this software w/ the L298 and the BBB w/ two DC brushed motors.

If you can see where I have gone wrong, please chime in. I am running out of ideas. I keep trying to support new software for this motor driver but I keep ending up empty.

The motors will not turn.

Seth

P.S. So, if you have some extra time, please reply.


On Wednesday, April 18, 2018 at 6:20:20 PM UTC-5, Mala Dies wrote:

Dennis Lee Bieber

unread,
May 3, 2018, 11:15:12 AM5/3/18
to beagl...@googlegroups.com
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/

Dennis Lee Bieber

unread,
May 3, 2018, 11:22:29 AM5/3/18
to beagl...@googlegroups.com
On Thu, 03 May 2018 11:14:51 -0400, Dennis Lee Bieber
<wlf...@ix.netcom.com> declaimed the following:


> 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
>

Whoops -- missed the "while True:" master loop... Ignore that comment

Mala Dies

unread,
May 3, 2018, 5:15:05 PM5/3/18
to BeagleBoard
Hello Sir,

Seth here. Mr. Dennis, I was looking over the ideas and software. I really appreciate you taking time out to make me understand what exactly I was "achieving" w/ my software ex. and the setup. I am actually attached from P9_21 and P9_22 only now. I realized that I might have to add more leads to the L298 Board to make the motors turn. 

I have taken away these leads to the L298 Board and now just using what I described. I see why you are right here. I have changed the software so many times, I forgot what exactly I was using.

I am not using En A or En B for my board. I will now, though. I had the jumper pins over the En A and En B pins on the L298 Board.

Seth

P.S. You have given me more ideas so far. Thank you, sir. I see where the m1a and m1b was doubled, w/out my looking over it, and caused the pin to be executed twice w/ the latter being the one used.

Mala Dies

unread,
May 3, 2018, 5:56:40 PM5/3/18
to BeagleBoard
Hello Sir,

Mr. Dennis...Seth here. Um, I am attaching the pins on P4 on the L298 Board to En A (2) to P9_21 and En B (8) to P9_22 as GPIOs. I am attempting this right now. So, I could not get your software to run. I tried this instead (so far).

import Adafruit_BBIO.GPIO as GPIO
import time

GPIO.setup("P9_21", GPIO.OUT)
GPIO.setup("P9_22", GPIO.OUT)

GPIO.output("P9_21", GPIO.HIGH)
GPIO.output("P9_22", GPIO.HIGH)

p1 = "P9_21"
p2 = "P9_22"

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)
        time.sleep(21)
    def stop(self):
        GPIO.output(self.p1, GPIO.LOW)
        GPIO.output(self.p2, GPIO.LOW)
    def forward(self):
        time.sleep(21)     #safety to avoid shock of reversals
        GPIO.output(self.p1, GPIO.HIGH)
        GPIO.output(self.p2, GPIO.LOW)
    def reverse(self):
        self.time.sleep(21)
        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
        time.sleep(21)
#GPIO.cleanup()


So...

This software runs and is done w/ a ms of time but it performs no actions just like my last software. 

...

I did remove the P9.12 and P9.15 leads from the Pins on the BBB to the L298 Board. So, I am attached to En A to P9.21 and En B to P9.22.

Seth

P.S. I will keep plugging at it. I know I changed up your software a lot or a little but I was receiving too many errors and I wanted to move on. If you have any recommendations so far as to what may drive these motors on the L298 Board, please do not hesitate to reply. Thank you again, sir. 

Mala Dies

unread,
May 3, 2018, 6:06:55 PM5/3/18
to BeagleBoard
Hello Again Sir,

Mr. Dennis...Seth here again. I also tried PWM as an output to the L298 Board. I listed some software below in case you wanted to view it. Oh and I tried w/ the while loop hashed out (#) and w/ it as it is now. Well, here it is:

#!/usr/bin/python

import Adafruit_BBIO.PWM as PWM
#import time

MotorOne = "P9_21"
MotorTwo = "P9_22"

PWM.start(MotorOne, 50, 20, 0)
PWM.start(MotorOne, 50, 20, 0)

while True:
    taco = (MotorOne, 1)
    bien = (MotorTwo, 1)
    print "I love Lucy!"

#for i in range(1, 30):
    #taco = (MotorOne, 30)
    #bien = (MotorTwo, 30)
    #print "I think Lucy is a cheat!"

#for i in range(1, 54):
    #taco = (MotorOne, 30, -1)
    #bien = (MotorTwo, 30, -1)
    #print "She probably is a cheat!"

PWM.stop(MotorOne)
PWM.stop(MotorTwo)
PWM.cleanup


So, you see. I cannot make PWM work or GPIO work on this board. I know it is me. It cannot be a faulty board. I push the power button after applying power, 12v 1.3Ah, and the LED stays lit. 

Seth

P.S. I understood what you typed in your last e-mail post in this forum on this subject. I was not expecting any certain outcome. I was testing software w/ this motor driver to see if things would just make the motors turn. It is that simple. Now, if the motors did turn and the recorded effect was pleasing, I would not have to change anything. But, if the motors turned incorrectly for me, I would then investigate further what I could do w/ the software to change this fact. 


On Thursday, May 3, 2018 at 10:15:12 AM UTC-5, Dennis Lee Bieber wrote:

Dennis Lee Bieber

unread,
May 3, 2018, 9:02:46 PM5/3/18
to beagl...@googlegroups.com
On Thu, 3 May 2018 14:15:05 -0700 (PDT), Mala Dies
<fun...@gmail.com> declaimed the following:

>P.S. You have given me more ideas so far. Thank you, sir. I see where the
>m1a and m1b was doubled, w/out my looking over it, and caused the pin to be
>executed twice w/ the latter being the one used.
>

In the code you had posted, m1a/m1b were not doing anything -- they
only appear on the left side of an "=". The right side executes, but the
contents there are immediates with no return value (or where strings that
don't do anything).

Dennis Lee Bieber

unread,
May 3, 2018, 9:32:52 PM5/3/18
to beagl...@googlegroups.com
On Thu, 3 May 2018 15:06:55 -0700 (PDT), Mala Dies
<fun...@gmail.com> declaimed the following:



>P.S. I understood what you typed in your last e-mail post in this forum on
>this subject. I was not expecting any certain outcome. I was testing
>software w/ this motor driver to see if things would just make the motors
>turn. It is that simple. Now, if the motors did turn and the recorded
>effect was pleasing, I would not have to change anything. But, if the
>motors turned incorrectly for me, I would then investigate further what I
>could do w/ the software to change this fact.
>

Take the motor controller out of the equation...

Run the GPIO through a decent resistor and LED (high side to GPIO, low
side to GND -- so the LED glows when the GPIO is set HIGH). Look at any
decent source for examples of LEDs from BBB (since the BBB has such low
power-handling you need to ensure the LED doesn't draw too much current).

http://www.toptechboy.com/beaglevone-black-rev-c/beaglebone-black-lesson-5-blinking-leds-from-gpio-pins/

Watch the LEDs -- if they don't change when running your code, then
either you are not commanding the GPIOs or your GPIO pins are damaged/dead.

Until you can see the GPIO LEDs changing with commands in your program,
anything else is irrelevant!

Then you can get fancier -- wire a pair of LEDs in opposite directions
(pick a green and a red) OR find a dual-color LED as used in
http://www.instructables.com/id/The-RedGreen-LED-Guide/
and then connect (with resistor) to the two GPIOs you intend to use for one
motor. Basically, this configuration will have the LED OFF if both pins are
the same state (motor stopped) and will show either green or red depending
on the direction you are driving the motor.


----

As for the Enable pins... The spec sheet has some confusingly nasty
comment

"""
Turn-On and Turn-Off : Before to Turn-ON the Supply Voltage and before to
Turn it OFF, the Enable input must be driven to the Low state.
"""

Taken literally, you can't just jumper them. You will need (at least) 1
GPIO (you could tie it to both En-A and En-B to toggle them both at the
same time) and set it HIGH before controlling the drive inputs.

You then need to set the inputs for a motor to OPPOSITE states to drive
the motor -- setting both to the same state is a STOP condition. That means
you need one input HIGH and the other input LOW /per controller channel/.
See the table in figure 6 (of the Sparkfun link, though I think both were
the same document).

En=HIGH, "C"=HIGH, "D"=LOW => "Forward"
En=HIGH, "C"=LOW, "D"=HIGH => "Reverse"
En=HIGH, "C" and "D" both HIGH OR LOW => HARD STOP
En=LOW, "C" and "D" can be anything => Soft/coast STOP

Presuming you use one GPIO for both ENables, you need five total GPIOs
to handle two motors.

Mala Dies

unread,
May 3, 2018, 9:37:17 PM5/3/18
to BeagleBoard
Hello...

m1a is now P9_21. m1b is now P9_22. P9_21 is attached to En A. P9_22 is attached to En B on the L298 board.

If I understand correctly, the old software is just bad. Now, although bad, I can make new software to suit the needs of this board. It has just taken me longer than expected for some reason. I am sure, as you can tell so far, you know by now I am highly novice on this subject and I have been a novice for a good amount of time.

Seth

P.S. I guess w/ no return value, the system fails. How do you think I should make a return value? 

Mala Dies

unread,
May 3, 2018, 9:40:41 PM5/3/18
to BeagleBoard
Yes Sir,

I will make sure my GPIO pins are working and I am in command of them first. I will set up some LED stuff and see if it works. I will reply soon.

Seth

Mala Dies

unread,
May 3, 2018, 10:06:04 PM5/3/18
to BeagleBoard
Hello Sir,

Seth here. Otay! LED hooked up and running on and off. Here is the software:

import Adafruit_BBIO.GPIO as GPIO
import time

GPIO.setup("P9_21", GPIO.OUT)

while True:
    GPIO.output("P9_21", GPIO.HIGH)
    time.sleep(3)
    GPIO.output("P9_21", GPIO.LOW)
    time.sleep(5)

I hooked up the P9_21 pin. Now, off to test P9_22. I will let you know.

Seth

Mala Dies

unread,
May 3, 2018, 10:39:35 PM5/3/18
to BeagleBoard
Mr. Dennis,

Seth here again. I got the software changed to P9_22 and tested the change in pin at P9_22. It makes the LED blink on and off repeatedly until I use control-c. 

Seth

P.S. Now, I read what you described. Thank you for the "En" ideas and info. I will try to dedicate some time to promoting this to software. 

Mala Dies

unread,
May 3, 2018, 10:47:40 PM5/3/18
to BeagleBoard
Hello Sir,

Just for a test, I ran the software for PWM while I had the LED attached to the BBB. The LED turned on. Do you think it may be the L298 board?

Seth

P.S. I know what you have described and I know it is not as easy as I am saying. I just wonder if you know of a way to test the board...maybe? If so, let me know. I can probe away if necessary. The board has a power LED that shines when I press the power button. It works. Shots in the dark, here.  

Dennis Lee Bieber

unread,
May 4, 2018, 9:45:14 AM5/4/18
to beagl...@googlegroups.com
On Thu, 3 May 2018 19:47:40 -0700 (PDT), Mala Dies
<fun...@gmail.com> declaimed the following:

>Hello Sir,
>
>Just for a test, I ran the software for PWM while I had the LED attached to
>the BBB. The LED turned on. Do you think it may be the L298 board?
>

No... I'm going to be somewhat blunt -- I think it is your
understanding of how the motor controller board works. (I'm also assuming
that you have the chip properly wired with the resistors and capacitors
recommended by the spec sheet... AND that the 3.3V HIGH from the BBB is
sufficient to be detected by the controller which was designed to work with
5V TTL level signals [TTL High is supposed to be around 2.4V, CMOS High is
70% of voltage, or 3.5V for 5V supply])

In pretty much all of your examples, you were setting both control pins
for a motor to the same value... And since you never had ENable and both
motor control inputs in the same program the odds are that anything could
be happening... The same value on the control inputs means "STOP" -- so of
course the motor is not spinning (even if you ENabled it).


To test one motor you'll need three GPIOs (I'm going to call them EN_A,
IN_A1, IN_A2)

Initialize:

Set all three to OUTPUT mode
Set EN_A to LOW (turn off motor controller)
Set IN_A1 and IN_A2 to LOW (ensure motor STOP settings)

then

Set EN_A to HIGH (turn on motor controller, motor still stopped)
delay some

Set IN_A1 to HIGH (motor should spin)
delay some

Set IN_A2 to HIGH (motor should stop)
delay some

Set IN_A1 to LOW (motor should spin in opposite direction)
delay some

Sent EN_A to LOW (motor should coast to a stop)

test done

Mala Dies

unread,
May 4, 2018, 4:09:42 PM5/4/18
to BeagleBoard
Hello Sir,

Seth here. Please view this photo of my L298 Board:


Sir,

Hello...this is the board. I read over the ideas you prompted me to understand. I will read the spec. sheet again (over and over). I realize I was missing ideas relating to this board. Thank you for bringing it to my attention. 

...

I will try some software that will get posted here but much later. I think this photo should describe some ideas that we were both lacking to understand b/c of our communication.

Seth

P.S. Thank you again for your service. 

Mala Dies

unread,
May 4, 2018, 9:49:43 PM5/4/18
to BeagleBoard
Hello Again Mr. Dennis,

Seth here. 

...

 To test one motor you'll need three GPIOs (I'm going to call them EN_A, 
IN_A1, IN_A2) 

Initialize: 

        Set all three to OUTPUT mode 
        Set EN_A to LOW (turn off motor controller) 
        Set IN_A1 and IN_A2 to LOW (ensure motor STOP settings) 

then 

        Set EN_A to HIGH (turn on motor controller, motor still stopped) 
        delay some 

        Set IN_A1 to HIGH (motor should spin) 
        delay some 

        Set IN_A2 to HIGH (motor should stop) 
        delay some 

        Set IN_A1 to LOW (motor should spin in opposite direction) 
        delay some 

        Sent EN_A to LOW (motor should coast to a stop)

This is what you typed out and thank you. I read the literature on the L298 and gave you a photo of the board I am using w/ this L298 dual H-Bridge. I will use what you have given me to produce some software soon. 

Seth

P.S. Three wires! Okay. I will set up three GPIO pins for this specific motor driver. I would have not figured out that I would have needed three wires for this specific board. Thank you, sir.

Dennis Lee Bieber

unread,
May 5, 2018, 12:23:11 AM5/5/18
to beagl...@googlegroups.com
On Fri, 4 May 2018 13:09:42 -0700 (PDT), Mala Dies
<fun...@gmail.com> declaimed the following:

>Hello Sir,
>
>Seth here. Please view this photo of my L298 Board:
>
><https://lh3.googleusercontent.com/-onhva_QOKrI/Wuy9QwO6QnI/AAAAAAAAJ6k/ip5cNEuXMeMjSIlxKovrNnVpKw6EYPcjgCLcBGAs/s1600/L298%2BBoard.jpg>
>
>Sir,
>
>Hello...this is the board. I read over the ideas you prompted me to
>understand. I will read the spec. sheet again (over and over). I realize I
>was missing ideas relating to this board. Thank you for bringing it to my
>attention.
>

Looking at that (some labels are covered by the wires -- I can't read
the labels of the three ports on the left; I'm presuming those are power
source for the motors). I think I can safely say there are not enough
control wires to do anything!

For the middle jumper posts...

I don't know about the 5V posts, and for the time being, take out the
ENB lead.

For the motor connected to OUT1/OUT2 you need to have leads on ENA, AND
you need connections to both IN1 and IN2 (you may need to jumper the 5V pin
to a source of 5V). IN1 and IN2 are the forward (High/Low)/stop (High/High
or Low/Low)/reverse (Low/High) control, which is only active if ENA is High

Dennis Lee Bieber

unread,
May 5, 2018, 12:27:28 AM5/5/18
to beagl...@googlegroups.com
On Fri, 4 May 2018 18:49:43 -0700 (PDT), Mala Dies
<fun...@gmail.com> declaimed the following:

>
>P.S. Three wires! Okay. I will set up three GPIO pins for this specific
>motor driver. I would have not figured out that I would have needed three
>wires for this specific board. Thank you, sir.
>

Three wires PER MOTOR (though you /could/ use one for both ENA and ENB
if you will always be controlling both at the same time -- using separate
controls for them would let you "idle" a motor rather than locking it in a
hard stop).

Mala Dies

unread,
May 5, 2018, 1:01:03 AM5/5/18
to BeagleBoard
Okay Sir,

I am going to set up one motor first, get that one motor working, and then use similar software to run both motors. Thank you for the pointers. I was unaware of each motor needing three wires from the BBB to the motor driver for forward, reverse, and backwards. 

Seth

P.S. I will keep you updated w/ what happens on the first motor software. I will post it in here once completed. Yea boy!

Mala Dies

unread,
May 5, 2018, 1:17:06 AM5/5/18
to BeagleBoard
Hello Sir,

Seth here. You have got a good set of shoulders on your head. This was my issue and you walked me through it. Thank you sir. See this software:

import Adafruit_BBIO.GPIO as GPIO
import time

MotorOne = "P9_21", "P9_22", "P9_12"

GPIO.setup("P9_21", GPIO.OUT)
GPIO.setup("P9_22", GPIO.OUT)
GPIO.setup("P9_12", GPIO.OUT)

EnA = GPIO.output("P9_21", GPIO.HIGH)
ln1 = GPIO.output("P9_22", GPIO.LOW)
ln2 = GPIO.output("P9_12", GPIO.LOW)

EnA = GPIO.output("P9_21", GPIO.HIGH)
ln1 = GPIO.output("P9_22", GPIO.LOW)
ln2 = GPIO.output("P9_12", GPIO.HIGH)

while True:

        try:
                for i in range (0, 9):
                    motorOne = ("P9_21", "P9_22", "P9_12")
                    time.sleep(3)
                    print "EnA", "\tln1", "\tln2"
                #for move in range (0, 9):
                    #ln1 = ("P9_22")
                    #ln2 = ("P9_12")
                    #time.sleep(3)
                    #print "ln1", "\tln2"

        except(KeyboardInterrupt):

                print "You have just ended your camping trip!"
                GPIO.cleanup()
                quit()


This software makes one motor go in one direction so far. I am sure I can figure out more but this is "as-is" for now. I listened to your commands and your intentions. You have helped. 

Seth

P.S. I guess I should make this motor understand what it needs to do from the BBB more and more until the motor can get commanded via control, e.g. PS2 controller or small remote, application online, or via just one random, completed set of software instructions. 

Dennis Lee Bieber

unread,
May 5, 2018, 12:21:12 PM5/5/18
to beagl...@googlegroups.com
On Fri, 4 May 2018 22:01:02 -0700 (PDT), Mala Dies
<fun...@gmail.com> declaimed the following:

>Okay Sir,
>
>I am going to set up one motor first, get that one motor working, and then
>use similar software to run both motors. Thank you for the pointers. I was
>unaware of each motor needing three wires from the BBB to the motor driver
>for forward, reverse, and backwards.
>
The three wires are one for enable, and two together that control
direction (it is not one wire for forward and one for reverse -- High/Low
is one direction, Low/High is the other direction, and when High/High OR
Low/Low it is STOP).

Consider if you connected the motor directly to a battery -- one wire
is + the other is -; to reverse the motor direction you have to swap the +
and - leads... That's what the High/Low vs Low/High combination is doing --
telling the controller to swap the power through the driver transistors.
The Enable acts like a power switch in-line with one of the wires.

https://en.wikipedia.org/wiki/H_bridge (the controller IC is smart enough
to prevent the short-circuit condition)

Mala Dies

unread,
May 6, 2018, 5:20:17 PM5/6/18
to BeagleBoard
Hello Sir,

Seth here, again. Thank you very much for your words. The ideas you have shared have helped thus far. I have been able to make my motor turn. Here is some software that may make no sense but I will keep on trying:

import Adafruit_BBIO.GPIO as GPIO
import time
from time import sleep

EnA = "P9_21"
ln1 = "P9_22"
ln2 = "P9_12"

print "Initialize"

GPIO.setup("P9_21", GPIO.OUT)
GPIO.setup("P9_22", GPIO.OUT)
GPIO.setup("P9_12", GPIO.OUT)

GPIO.output("P9_21", GPIO.LOW)
GPIO.output("P9_22", GPIO.LOW)
GPIO.output("P9_12", GPIO.LOW)

while True:

    for i in range(10):
        EnA = GPIO.output("P9_21", GPIO.HIGH)
    for i in range(3):
        ln1 = GPIO.output("P9_22", GPIO.HIGH)
    for i in range(5):
        ln2 = GPIO.output("P9_12", GPIO.HIGH)
    for i in range(4):
        ln1 = GPIO.output("P9_22", GPIO.LOW)
    for i in range(10):
        EnA = GPIO.output("P9_21", GPIO.LOW)
        print "Go, Go Bananas!"

        try:
except KeyboardInterrupt:
    print "I got it over w/!"
GPIO.cleanup()
quit(sleep)

I think this may just make the motor turn at a very slow pace. I stop the software and the motor turns at a regular pace. W/ this software, I have not been able to turn the motor in reverse yet. I will change up the software soon.

Seth

P.S. If you see where the software is defaulting to an error, please let me know. It runs but it does not do what I would have expected it to do (thus far). 

Mala Dies

unread,
May 6, 2018, 7:28:25 PM5/6/18
to BeagleBoard
Hello Sir,

I am starting to understand more of what you were describing to me. Look here:

import Adafruit_BBIO.GPIO as GPIO
import time

Master_Pin =  "P9_21"
ln1 =         "P9_22"
ln2 =         "P9_12"

if __name__=="__main__":

    GPIO.setup(Master_Pin, GPIO.OUT)
    GPIO.output(Master_Pin, GPIO.LOW)

    GPIO.setup(ln1, GPIO.OUT)
    GPIO.setup(ln2, GPIO.OUT)

    GPIO.output(Master_Pin, GPIO.HIGH)
    GPIO.output(ln1, GPIO.HIGH)
    GPIO.output(ln2, GPIO.LOW)
    time.sleep(5)

    GPIO.output(Master_Pin, GPIO.HIGH)
    GPIO.output(ln1, GPIO.LOW)
    GPIO.output(ln2, GPIO.HIGH)
    time.sleep(5)
    print "I love your body Larry!"

    GPIO.output(Master_Pin, GPIO.LOW)

    GPIO.output(Master_Pin, GPIO.LOW)
    GPIO.cleanup()



Thank you again for your help.

Seth

Dennis Lee Bieber

unread,
May 6, 2018, 9:46:45 PM5/6/18
to beagl...@googlegroups.com
On Sun, 6 May 2018 14:20:17 -0700 (PDT), Mala Dies
<fun...@gmail.com> declaimed the following:


>while True:
>
> for i in range(10):
> EnA = GPIO.output("P9_21", GPIO.HIGH)

1) the variable names on the left of useless as they are never
referenced anywhere else in the code.

2) this loop just sets the pin to the SAME VALUE 10 times in a row.

> for i in range(3):
> ln1 = GPIO.output("P9_22", GPIO.HIGH)

3 times, same value

> for i in range(5):
> ln2 = GPIO.output("P9_12", GPIO.HIGH)

5 times...

> for i in range(4):
> ln1 = GPIO.output("P9_22", GPIO.LOW)

4 times...

> for i in range(10):
> EnA = GPIO.output("P9_21", GPIO.LOW)
> print "Go, Go Bananas!"

10 times, with a repeated print statement.


The total effect condenses down to (and to make it more clear, I'm
going to set up "constants" for the pins):

ENA = "P9_21"
IN1 = "P9_22"
IN2 = "P9_12"
# I'm presuming the default startup state is all GPIO's LOW, but one
#should check the documentation for the BBB to confirm
while True:
GPIO.output(ENA, GPIO.HIGH) #enable motor control, motor in STOP
time.sleep(0.1) #or however long 10 calls to GPIO_output consume
GPIO.output(IN1, GPIO.HIGH) #motor running FORWARD
time.sleep(0.03) #or however long 3 calls takes to execute
GPIO.output(IN2, GPIO.HIGH) #motor in STOP
time.sleep(0.05) #or whatever 5 calls takes
GPIO.outputIN1, GPIO.LOW) #motor running REVERSE
time.sleep(0.04) #or whatever 4 calls takes
GPIO.output(ENA, GPIO.LOW) #motor coasting to stop
time.sleep(0.2) #assumes 10 calls and 10 prints

Note that, since the state was REVERSE when you disabled control, the
next pass of the loop will START in REVERSE when you enable control. THEN
when you set IN1 to HIGH, the motor will go to hard stop (since IN2 is
still HIGH from the first time through the loop). It will stay in STOP
until you set IN1 to LOW, when it again will run in REVERSE until the ENA
is turned off.

Jason Kridner

unread,
May 7, 2018, 11:31:59 AM5/7/18
to beagl...@googlegroups.com
All worked out now as part of https://www.hackster.io/silver2row/beaglebone-black-and-l298-motor-driver-in-python-2156be ? 

Good timing as BeagleBoard.org Motor Cape (https://github.com/beagleboard/capes/blob/master/beaglebone/designs/Motor/Motor_Cape_sch.pdf, https://beagleboard.org/capes) is about to start shipping to distributors. It'll likely go out in about 2 weeks, depending on when I get https://github.com/jadonk/beagle-tester updated for it.

--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/9v8vedt460upknng78b9j6ec2vpaq9l20k%404ax.com.
For more options, visit https://groups.google.com/d/optout.
--

Mala Dies

unread,
May 7, 2018, 6:01:49 PM5/7/18
to BeagleBoard
Yes Sir,

I got a fellow zmatt, Mr. Dennis, and a fellow on Adafruit-Forums all to give advice. Although I ended up taking another route, they all had supportive advice I could follow and adhere to. 

Seth

P.S. Thank you for the ideas and new Capes. I got two on backorder as I type this message out. I got the LoadCape and RelayCape. I will get the MotorCape later. I even signed up for your presentation you plan on making in the form of a webinar on Element14.

Mala Dies

unread,
May 8, 2018, 2:43:57 PM5/8/18
to BeagleBoard
Hello Mr. Dennis,

Seth here. I made some other software that I want to try to describe to you. Here goes it:

import Adafruit_BBIO.GPIO as GPIO
import time
from time import sleep

EnA = "P9_21"
ln1 = "P9_22"
ln2 = "P9_12"

print "Initialize"

GPIO.setup("P9_21", GPIO.OUT)
GPIO.setup("P9_22", GPIO.OUT)
GPIO.setup("P9_12", GPIO.OUT)

GPIO.output("P9_21", GPIO.LOW)
GPIO.output("P9_22", GPIO.LOW)
GPIO.output("P9_12", GPIO.LOW)

while True:

    for i in range(1):
        EnA = GPIO.output("P9_21", GPIO.HIGH)
        time.sleep(2)
    for i in range(1, 9):
        ln1 = GPIO.output("P9_22", GPIO.HIGH)
        ln2 = GPIO.output("P9_12", GPIO.LOW)
        time.sleep(2)
    for i in range(1, 7):
        ln1 = GPIO.output("P9_22", GPIO.LOW)
        ln2 = GPIO.output("P9_12", GPIO.HIGH)
        time.sleep(2)
    for i in range(1):
        EnA = GPIO.output("P9_21", GPIO.LOW)
        time.sleep(2)
        print "Go, Go Bananas!"
    for i in range(1):
        EnA = GPIO.output("P9_21", GPIO.HIGH)
        time.sleep(1)
    for i in range(1):
        ln1 = GPIO.output("P9_22", GPIO.HIGH)
        ln2 = GPIO.output("P9_12", GPIO.LOW)
        time.sleep(2)
    for i in range(1):
        EnA = GPIO.output("P9_21", GPIO.LOW)
        ln1 = GPIO.output("P9_22", GPIO.LOW)
        ln2 = GPIO.output("P9_12", GPIO.LOW)
        time.sleep(2)

        try:
            print "Um...what is happening?"
            time.sleep(2)

        except(KeyboardInterrupt):
            print "I got it over w/!"
            GPIO.cleanup()