dionryl1995
Posts: 2
Joined: Fri Aug 02, 2019 11:06 am

Pass and Fail counter with GPIO and tkinter

Fri Aug 02, 2019 3:40 pm

Hi,

I need help.
I'm creating a code to build a counter for "PASSED AND FAILED counter" with GPIO and display the counter value using tkinter.

Here's the condition:
1. Pressing "Start Test" button it will ready for counting.
2. I need a condition that two GPIO input detect it will count specific counter:
a. GPIO.setup(11,GPIO.IN) and GPIO.setup(13,GPIO.IN) detects it will count the "CountPass".
b. GPIO.setup(11,GPIO.IN) and GPIO.setup(15,GPIO.IN) detects it will count the "CountFail".
3. by Pressing the button "End Test" reset all the counter.

Thank you,
tkinter.PNG
Tkinter Display
tkinter.PNG (5.17 KiB) Viewed 156 times
I tried this code:

Code: Select all

from tkinter import*
import RPi.GPIO as GPIO
import time


def Start_counter():
    global CountPass
    global CountFail

    GPIO.add_event_detect(13,11, GPIO.RISING, callback = buttonPressed)
    GPIO.add_event_detect(15,11, GPIO.RISING, callback = buttonFailed)


def buttonPressed():
    CountPass.set(CountPass.get() + 1)


def buttonFailed():
    CountFail.set(CountFail.get() + 1)



def End_counter():
    CountPass.set(0)
    CountFail.set(0)


root = Tk()
GPIO.setmode(GPIO.BOARD)

#========GPIO pin configuration===================
GPIO.setup(11,GPIO.IN) #EOT (Start Of Test) GPIO pin
GPIO.setup(13,GPIO.IN) #PASS  GPIO pin
GPIO.setup(15,GPIO.IN) #Fail GPIO pin

CountPass = IntVar()
CountPass.set(0)
CountFail = IntVar()
CountFail.set(0)

#================================

Button(root, text = "Start Test", command = Start_counter).grid(row = 0, column = 0)
Button(root, text = "End Test", command = End_counter).grid(row = 0, column = 1)

Label(root, text = "Passed counter:").grid(row = 1, column = 0,sticky = E,padx = 20, pady = 10)
Label(root, text = "Failed counter:").grid(row = 2, column = 0,sticky = E,padx = 20, pady = 10)

Label(root, textvariable = CountPass, bg = 'white', width = 10).grid(row = 1, column = 1,sticky = W,padx = 20, pady = 10)

Label(root, textvariable = CountFail,bg = 'white', width = 10).grid(row = 2, column = 1,sticky = W,padx = 20, pady = 10)


mainloop()

ghp
Posts: 1408
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Pass and Fail counter with GPIO and tkinter

Fri Aug 02, 2019 7:26 pm

Hmm, and where is the problem ?

gordon77
Posts: 4162
Joined: Sun Aug 05, 2012 3:12 pm

Re: Pass and Fail counter with GPIO and tkinter

Sat Aug 03, 2019 11:34 am

Try this..

You have to click START button and then GPIO11 has to be pressed to count inputs on 13 and 15.

Code: Select all

from tkinter import*
import RPi.GPIO as GPIO
import time

ECT = 11
PASS = 13
FAIL = 15

def Start_counter():
    global CountPass
    global CountFail
    GPIO.add_event_detect(PASS, GPIO.RISING, callback = buttonPressed)
    GPIO.add_event_detect(FAIL, GPIO.RISING, callback = buttonFailed)



def buttonPressed(X):
    if GPIO.input(ECT) == 1:
       CountPass.set(CountPass.get() + 1)


def buttonFailed(X):
    if GPIO.input(ECT) == 1:
       CountFail.set(CountFail.get() + 1)



def End_counter():
    CountPass.set(0)
    CountFail.set(0)


root = Tk()

#========GPIO pin configuration===================
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(ECT,GPIO.IN,pull_up_down = GPIO.PUD_DOWN)  #ECT (Enable CounT) GPIO pin
GPIO.setup(PASS,GPIO.IN,pull_up_down = GPIO.PUD_DOWN) #PASS  GPIO pin
GPIO.setup(FAIL,GPIO.IN,pull_up_down = GPIO.PUD_DOWN) #Fail GPIO pin

CountPass = IntVar()
CountPass.set(0)
CountFail = IntVar()
CountFail.set(0)

#================================

Button(root, text = "Start Test", command = Start_counter).grid(row = 0, column = 0)
Button(root, text = "End Test", command = End_counter).grid(row = 0, column = 1)

Label(root, text = "Passed counter:").grid(row = 1, column = 0,sticky = E,padx = 20, pady = 10)
Label(root, text = "Failed counter:").grid(row = 2, column = 0,sticky = E,padx = 20, pady = 10)

Label(root, textvariable = CountPass, bg = 'white', width = 10).grid(row = 1, column = 1,sticky = W,padx = 20, pady = 10)

Label(root, textvariable = CountFail,bg = 'white', width = 10).grid(row = 2, column = 1,sticky = W,padx = 20, pady = 10)


mainloop()

dionryl1995
Posts: 2
Joined: Fri Aug 02, 2019 11:06 am

Re: Pass and Fail counter with GPIO and tkinter

Sat Aug 03, 2019 1:11 pm

Thank u sir. I will try it and I ask again if not functioning

Return to “Python”