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

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.

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!

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

Hello…

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

Seth

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

`

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 Wed, 2 May 2018 21:51:08 -0700 (PDT), Mala Dies
<functt@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)

On Thu, 03 May 2018 11:14:51 -0400, Dennis Lee Bieber
<wlfraed@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

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.

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

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

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 Thu, 3 May 2018 14:15:05 -0700 (PDT), Mala Dies
<functt@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).

On Thu, 3 May 2018 15:06:55 -0700 (PDT), Mala Dies
<functt@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

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.

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?

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

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

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.

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.

On Thu, 3 May 2018 19:47:40 -0700 (PDT), Mala Dies
<functt@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

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.

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.