-2

I am using Python, Adafruit_BBIO for GPIO and PWM, Flask, and a BeagleBone Black. With all these tools and info, I have been following along in a book, "Getting Started with BeagleBone" (Richardson 2014).

With this in mind, here is my software from the text:

from flask import Flask, render_template
app = Flask(__name__)
import Adafruit_BBIO.GPIO as GPIO
import Adafruit_BBIO.PWM as PWM

PWM.start("P8_13", 0.0)

@app.route("/")
def hello():
    if GPIO.input("P8_11"):
        doorStatus = "open"
    else:
        doorStatus = "closed"
    templateData = {
        'doorStatus': doorStatus,
    }
    return render_template('main-door.html', **templateData)

@app.route('/ledLevel/<level>')
def pin_state(level):
    PWM.set_duty_cycle("P8_13", float(level))
    return "LED level set to " + "."

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=5000, debug=True)

So...I have:

Flask: v0.12.2 Python: v2.7.13

I am using the 4.9.x kernel from a Debian Distro, Stretch.

Here is my print out of the info. for the error when running the software:

![Image of Issue][1]

The terminal goes to the debugger online. I check the online debugger out and the above link is what is produced.

Seth

P.S. NameError: Global Name P8_11 is not defined.

De Funct
  • 336
  • 1
  • 10

2 Answers2

0
from flask import Flask, render_template
app = Flask(__name__)
import Adafruit_BBIO.GPIO as GPIO
import Adafruit_BBIO.PWM as PWM

GPIO.setup("P8_19", GPIO.OUT)
PWM.start("P8_11", 0.0)

@app.route("/")
def hello():
    if GPIO.input("P8_19"):
        doorStatus = "open"
    else:
        doorStatus = "closed"
    templateData = {
        'doorStatus': doorStatus,
    }
    return render_template('main-door.html', **templateData)

@app.route('/ledLevel/<level>')
def pin_state(level):
    PWM.set_duty_cycle("P8_11", float(level))
    return "LED level set to " + "."

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=5000, debug=True) 

This updated software should work if checked. I did not listen enough to the debugger online.

Seth

P.S. If you need extra support for Adafruit_BBIO, please check on https://github.com/adafruit/adafruit-beaglebone-io-python.

De Funct
  • 336
  • 1
  • 10
  • I jacked up the P8_ pin numbers on the software. It is actually backwards. The GPIO.setup is GPIO.setup("P8_11", GPIO.OUT) and PWM.start is PWM.start("P8_19, 0.0). Sorry. – De Funct Oct 12 '17 at 01:47
0

There was a bug in the PWM pins on Debian Stretch for Adafruit_BBIO.

Seth

P.S. Backup to kernel 4.4.x instead of using kernel 4.9.x.

De Funct
  • 336
  • 1
  • 10