1

So I am trying to have a pop up warning window when a GPIO pin on the Beagleboard is set to high. I have code that works easily in the console using the BBIO Library given my Adafruit. However when using the same logic applied to the pyside library, the program ignores the "if" clause and runs the popup automatically. Even with simple popups, the program ignores the if statement. Any help or ideas are appreciated.

    #console code
    import Adafruit_BBIO.GPIO as GPIO
    from time import sleep #handy sleep command
    GPIO.setup("P8_16", GPIO.IN)

    while True:
        if GPIO.input("P8_16"):
            print ("Battery Low on the Down low!!")
            sleep (1.25)
        else:
            pass

    #popup code
    import sys
    from PySide.QtCore import *
    from PySide.QtGui import *
    import time
    import Adafruit_BBIO.GPIO as GPIO
    from time import sleep #handy sleep command

    GPIO.setup("P8_16", GPIO.IN) #set GPIO port

    while True:
        if GPIO.input("P8_16"):
            #sleep(1)
            def window():
                app = QApplication(sys.argv)
                w = QWidget()
                b = QPushButton(w)
                b.setText("Battery is Low!")

                b.move(100,100)
                b.clicked.connect(showdialog)
                w.setWindowTitle("Battery Alert")
                w.show()
                sys.exit(app.exec_())

            def showdialog():
                msg = QMessageBox()
                msg.setIcon(QMessageBox.Warning)

                msg.setText("Please recharge the Tracker battery")
                msg.setInformativeText("To exit simply close the windows")
                msg.setWindowTitle("Battery Low")
                msg.setDetailedText("Please recharge the Tracker unit")
                msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
                msg.buttonClicked.connect(msgbtn)

                retval = msg.exec_()
                print "value of pressed message box button:", retval

            def msgbtn(i):
                print "Button pressed is:",i.text()

            if __name__ == '__main__': 
                window()

        else:
            pass
            sleep(1)
  • So you're claiming that the pyside imports somehow change the output of `GPIO.input("P8_16")`? Thus, if those two import lines are commented out, the script behaves "normally"? The only other real difference is that you have `sleep(1)` in the `else` branch of the second script, but not the first. – ekhumoro Nov 07 '16 at 17:42

0 Answers0