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