Python Forum
Raspberry PI Counter Project [HELP]
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Raspberry PI Counter Project [HELP]
#1
We have been tasked to create a counter with a GUI using raspberry pi (Python). The counter will be counting boxes on a production line using a sensor. However we are having problems getting the GPIO input pin to add one to our onscreen counter when the sensor is made. Any help would be greatly appreciated as we are at a loose end.



Our code so far

from Tkinter import *
import RPi.GPIO as GPIO
import time
from time import sleep
 
 
#main window
root = Tk()
root.configure(background="black")
root.geometry("1150x800")
root.title("Ligmatec 2 Counter")
    
#Global roots
global counter
counter = 0
 
#Button commands
def nClick():
    global counter
    counter += 1
    label1.config(text = counter)
    if GPIO.input(channel):
        counter += 1
    else:
        counter += 0
        
    #mButton1.config(text = counter)
 
def nClick1():
    global counter
    counter -= 1
    label1.config(text = counter)
    #mButton1.config(text = counter)
 
def nClick2():
    global counter
    counter = 0
    label1.config(text = counter)
    #mButton1.config(text = counter)
 
 
 
#buttons
#mButton1 = Button(text = counter)
label1 = Label(root, text="0", bg="black", fg="white")
mButton2 = Button(text="+ 1", bg="black", fg="white", command = nClick)
mButton3 = Button(text="- 1", bg="black", fg="white", command = nClick1)
mButton4 = Button(text="Reset", bg="black", fg="white", command = nClick2)
 
#Button Config files
mButton2.config(font=("arial", 48, "bold"))
mButton3.config(font=("arial", 48, "bold"))
label1.config(font=("arial", 72, "bold"))
#mButton1.config(font=("arial", 75, "bold"))
         
         
         
#mButton1.pack()
mButton2.pack()
mButton3.pack()
mButton4.pack()
label1.pack()     
root.mainloop()
 
 
 
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.IN)
GPIO.setup(11, GPIO.OUT)
counter=0
 
def counterPlus(channel):
    global counter
    if GPIO.input(channel):
        counter += 1
    else:
        counter += 0
        
 
GPIO.add_event_detect(7, GPIO.FALLING, callback=counterPlus, bouncetime=3)
 
 
time.sleep(1)
for x in range(0,500):
    time.sleep(2)
 
GPIO.cleanup()
Reply
#2
Hi
Did you manage to get your project up and running?

regards kobus
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020