1

I wrote a code for an app which will directly compare images and give output using Pyside2. The output will be displayed in the GUI as well as in LED connected through Arduino Uno using Pyfirmata. Now, I want my program to be executed in both Virtual mode (through GUI 'Run' button) and Physical mode (through a pushbutton connected in Arduino Uno. When this button is pushed, the Run part of the code will execute).

I tried to do this by programming the while loop (which reads the pushbutton status and execute the code whenever it is clicked) inside the main of Pyside2 code. But, when executed, only the Physical mode (through the pushbutton) is working and I'm unable to use the GUI's Run button. That is, the GUI executes the program when push button is clicked, and then goes to not responding. It stays that way until the pushbutton is clicked again. I'm unable to use the GUI's Run button completely.

I'm new to Python, Pyside and Pyfirmata. Could someone please help me with this?

The code is something like this.

class Ui_xxx(object):
    

    def setupUi(self, xxx):
        content
        self.retranslateUi(xxx)
        QtCore.QMetaObject.connectSlotsByName(xxx)

        self.button1.clicked.connect(self.button1)
        self.button2.clicked.connect(self.button2)
        self.button3.clicked.connect(self.button3)
        self.button4.clicked.connect(self.button4)
        self.say_run.clicked.connect(self.say_run)
  

    def retranslateUi(self, xxx):
        content

    def button1(self):
        content
                
        
    def button2(self):
        content
        
    def button3(self):
        content
        self.say_run()  
        
    def button4(self):
        content

    def say_run(self):
        QtCore.QCoreApplication.processEvents()
        content
        if os.listdir(dir1) == []:
            content
            
        else:   
            content

@goto.with_goto
def main():
    global board
    board = pyfirmata.Arduino('COM3')
    import sys
    app = QtWidgets.QApplication(sys.argv)
    xxx = QtWidgets.QMainWindow()
    ui = Ui_xxx()
    ui.setupUi(xxx)
    xxx.show()
    time.sleep(5)    
    it = pyfirmata.util.Iterator(board)
    it.start()
    digital_input = board.get_pin('d:5:i')
    def ws():
        while True:
            sw = digital_input.read()
            if sw is True:
                board.digital[12].write(1)
                time.sleep(5)
                board.digital[12].write(0)
                time.sleep(5)
                ui.say_run()
                QtCore.QCoreApplication.processEvents()
                break
    
    label .loop101
    ws()
    QtCore.QCoreApplication.processEvents()
    goto .loop101

    board.exit()
    sys.exit(app.exec_())

Reva S
  • 11
  • 1

0 Answers0