RE: MotorCape and Software/Getting Four Motors to Move w/ a 12v Battery...

Hello,

I have a BBBW and MotorCape. I have tested some motors on each of the screw connectors on the MotorCape. Success! Anyway, when controlling four motors at once, I have come across some issues.

My issue pertains to a Flask application w/ HTML to control the four motors via a website online.

Here is some software to test out if you have the MotorCape:

`

#!/usr/bin/python3

w/ help from #beagle on Freenode

from flask import Flask, render_template
import Adafruit_BBIO.GPIO as GPIO
import Adafruit_BBIO.PWM as PWM
import time

class Motor:
def init(self, dir_pin, pwm_pin, pwm_freq):
self.dir_pin = dir_pin
self.pwm_pin = pwm_pin
self.value = 0

PWM.start(pwm_pin, 0, pwm_freq)
GPIO.setup(dir_pin, GPIO.OUT)

def set(self, value):
assert -100 <= value <= 100
if (value < 0) != (self.value < 0):

changing direction

PWM.set_duty_cycle(self.pwm_pin, 0)
GPIO.output(self.dir_pin, value < 0)
PWM.set_duty_cycle(self.pwm_pin, abs(value))
self.value = value

motor1 = Motor(dir_pin=“P8_18”, pwm_pin=“P9_16”, pwm_freq=2000)
#motor2 = Motor(dir_pin=“P8_16”, pwm_pin=“P9_14”, pwm_freq=2000)
#motor3 = Motor(dir_pin=“P8_14”, pwm_pin=“P8_13”, pwm_freq=2000)
motor4 = Motor(dir_pin=“P8_26”, pwm_pin=“P8_19”, pwm_freq=2000)

app = Flask(name)
@app.route("/")
@app.route("/")

def updates(state=None):
if state == “F”:
motor1.set(100)
motor4.set(100)
time.sleep(.2)
if state == “L”:
motor1.set(0)
motor4.set(85)
time.sleep(.2)
if state == “R”:
motor1.set(85)
motor4.set(0)
time.sleep(.2)
if state == “S”:
motor1.set(0)
motor4.set(0)
time.sleep(.2)
if state == “REV”:
motor1.set(-75)
motor4.set(-75)
time.sleep(.2)
if state == “REV_L”:
motor1.set(-75)
motor4.set(0)
time.sleep(.2)
if state == “REV_R”:
motor1.set(0)
motor4.set(-75)
time.sleep(.2)

template_data = {
“title” : state,
}
return render_template(“boboIV.html”, **template_data)

if name == “main”:
app.run(host=“0.0.0.0”, port=5000, debug=True)

`

Everything is “Pythonic” in the software but this C & P did not do it justice. You can see why. Anyway…here is the HTML software too.

`

{{ status }}

MotorCape and BBBW!

This is a quick example on making motors move!

Agent One

More text and fun makings in life...

Get ready to control some motors!

Agent Two

This bunch of online buttons will make your motors move

FORWARD

LEFT RIGHT

STOP

REVERSE

REVERSE_L REVERSE_R

Agent Three

I hope you had fun controlling your motors!

Two, DC motors, a 12v battery, and a BBBW w/ MotorCape!

`

That HTML software just makes a nice website that I got mostly from w3schools.com.

Seth

P.S. If you know why this software does not make the motors move, please let me know. I have worked w/ the MotorCape and I am not sure if I need to use config-pin, a u-boot overlay, or some type of whatever.

Hello Again,

This is my idea. Motor1 and Motor4 is on one of the L298 chips. I could be wrong. Is this a fact?

Seth

P.S. I was thinking that my four motors are not working any longer b/c of the fact that the leads got put in the incorrect screw terminals. Does this sound like it is possible? For instance, I put the Motor1 and Motor2 leads in screw terminals for Motor1 and Motor4. Does this make sense?

Hello Once More,

Just for reference, the web application comes up w/ me enabling a .service file on the BBBW. The website has worked w/ other BBBW related flask-motor-html pages and motor movement.

Another factor is this…the bot, this four motor machine, moves w/ one board w/ the same software but not the other BBBW w/ the same software.

Seth

P.S. If you have any ideas, please do not hesitate to ask any questions for more info. and/or give advice. I have this date coming up and I want to have this bot working for this specific date, e.g. w/ the BBBW, MotorCape, and four motors.

Can you take a picture of how you have it wired?

Yes Sir,

Sure…I will reply once the vehicle/bot is photographed.

Seth

P.S. I can only show the MotorCape, BBBW, and leads though. The motors are buried in the bot as of now. Does me not showing the motor wiring matter? I know it does but the bot is fully assembled and will take longer to get a photograph across.

Hey Sir,

Here it goes: https://photos.app.goo.gl/QjGkPzCCt5g65B7CA.

Seth

P.S. That shows the pair of leads per motor attached to the MotorCape and the 12v battery leads that go from the battery to the MotorCape. Also sir, the power supply for the BBBW is a USB to jack. It turns the board on and powers it well. I have been able to make movement so far w/ motors but they are not acting in accordance to what I have expected. I figured one of the L298 drivers was switched upside down. I cannot be sure of this idea. Anyway, if you cannot view the photo, please reply one day.

Oh and Sir,

One last thing…there are many ways to fix this “issue.” There was a nice person on Freenode at #beagle that was kind enough to help me w/ software ideas in Python.

I could rewire the motors, use this person’s software, and/or change the complete idea of the software entirely.

Seth

P.S. I was thinking that the MotorCape, w/ the placement of the L298 drivers, was in accordance w/ the schematic. I think while the Cape is in accordance w/ the schematic, I should not expect anything other than rewiring my motors (well…two of them anyhow). If I was to use the software from Freenode, it may get more complicated on my end but may be worth it (learning and trying new things in software programming is the idea). So um, this is what I am hinting towards right now. Should I expect the MotorCape to run in a loop if all motors are told to move forward b/c of the placement of the L298 drivers? Yea, I think that is it for now. I will try to stay patient. I have too many ideas and little time. I am showing off the bot, BeagleBone Black Wireless, and MotorCape at a tiny Maker Faire soon. Um…yep. That is all for now. Sorry for the PS crap and this elongated explanation.

Several responses below…

Oh and Sir,

One last thing…there are many ways to fix this “issue.” There was a nice person on Freenode at #beagle that was kind enough to help me w/ software ideas in Python.

Probably ‘zmatt’.

I could rewire the motors, use this person’s software, and/or change the complete idea of the software entirely.

Seth

P.S. I was thinking that the MotorCape, w/ the placement of the L298 drivers, was in accordance w/ the schematic. I think while the Cape is in accordance w/ the schematic, I should not expect anything other than rewiring my motors (well…two of them anyhow). If I was to use the software from Freenode, it may get more complicated on my end but may be worth it (learning and trying new things in software programming is the idea). So um, this is what I am hinting towards right now. Should I expect the MotorCape to run in a loop if all motors are told to move forward b/c of the placement of the L298 drivers?

The cape itself isn’t running code, so I’m not sure what you mean. The PWMs will run free, so, once you set the drive strength, they’ll keep driving even if you don’t update things in the software.

Yea, I think that is it for now. I will try to stay patient. I have too many ideas and little time. I am showing off the bot, BeagleBone Black Wireless, and MotorCape at a tiny Maker Faire soon. Um…yep. That is all for now. Sorry for the PS crap and this elongated explanation.

Cool. We’ll try to help.

Can you take a picture of how you have it wired?

Thanks. Looks right from what I can see, but I don’t see the motor wiring itself. Seems to match capes/beaglebone/Motor at master · beagleboard/capes · GitHub.

Hello Once More,

Just for reference, the web application comes up w/ me enabling a .service file on the BBBW. The website has worked w/ other BBBW related flask-motor-html pages and motor movement.

You are testing the motors with simple code first, right?

Another factor is this…the bot, this four motor machine, moves w/ one board w/ the same software but not the other BBBW w/ the same software.

That simply tells me they are not the same. Can you find the difference?

Seth

P.S. If you have any ideas, please do not hesitate to ask any questions for more info. and/or give advice. I have this date coming up and I want to have this bot working for this specific date, e.g. w/ the BBBW, MotorCape, and four motors.

Hooking an oscilliscope up to see the output at the motors is always helpful.

Hello,

I have a BBBW and MotorCape. I have tested some motors on each of the screw connectors on the MotorCape. Success! Anyway, when controlling four motors at once, I have come across some issues.

Do you know if you are providing enough current in to the board? Can you monitor the voltage at the input and the output with a scope to see if there is droop?

Hello,

Yes…zmatt was the person that helped out.

I will check the oscilloscope soon. I think I figured out what happened.

The bot, which has four motors, is wired incorrectly due to me using an inline version of the L298 chips, e.g. Motor1 or M1 is hooked up to the front left and Motor2 or M3 was hooked up to the back left.

This created more issues than I would like to mention.

Seth

P.S. I just need to switch some leads and everything will be correct for once. It has been my fault this entire time. I was reaching out to see if there were any issues that people have stated about the Cape in question. I should have questioned myself. Thank you for your replies, sir.

Oh and Hello Again,

For the record, everything does work as expected if I think differently. I was thinking tank style w/ one of the L298 drivers being front left and back left on the bot.

Seth

P.S. “My bad.” I actually forgot to review the schematic again and again. I forgot about how the drivers were set up on the MotorCape.

Hello Sir,

This should be my last transmission on this subject unless you need any additional ideas:

def updates(state=None): motor1.set(-100) motor2.set(100) motor3.set(-100) motor4.set(100)

The above snippet is now forward on the bot. Although this is not prime or intended, I am not taking the bot apart to fix wiring as of now.

And…I went w/ the change in software instead of change of wiring b/c everything is already put together. Lazy!

Seth

P.S. So now, I have a forward, left, right, reverse, left_reverse, right_reverse, rotate_left, and rotate_right. This should be okay for the show for now.

Thanks for your experience and example code.

Hey Sir,

Yes sir…you are welcome but I could have not done this project w/out the book, “BeagleBone by Example,” by Prabakar.

Seth

P.S. I thought that persons’ ideas were creative and interesting. So, I tried them out and things developed from that point. Oh and sir, sorry for the lack of research on my part w/ schematics and testing. I thought I knew what I was saying.