Python Forum

Full Version: Wine / liquor dispenser project code issue
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi i am working on a wine dispenser.i am using raspberry pi to turn on GPIO relay solenoids with hall flowmeter.
everything is working but when it comes to turn on clean solenoid it start fluctuating (clicking).
Idea :
press a button
turn on first solenoid
flowmeter read pulses and turn off first solenoid to stop pouring
than on 2nd clean solenoid for 2 seconds ( which is flickering )
along with flowmeter i need to turn off first solenoid in 10 sec time just incase flowmeter failed to send pulse so solenoid will not burn out.
i tried to use external supply for flowmeter and solenoid relays but still same issue.
here are the codes
from gpiozero import Button, LED
from signal import pause
from time import sleep
import threading
import time
pulse = Button(23)
button_small = Button(18) # first button to  pour small
button_medium = Button(21) # 2nd  button to pour medium
button_big = Button(22) # 3rd  button to pour big
solenoid = LED(17)
clean = LED(25)

GAS_PAUSE = 0.05
TIME_OUT = 10.0

MEASURE_SMALL = 80
MEASURE_MEDIUM = 130
MEASURE_BIG = 200


def pour_small():
    start_pour(MEASURE_SMALL)

def pour_medium():
    start_pour(MEASURE_MEDIUM)

def pour_big():
    start_pour(MEASURE_BIG)

def kill_loop():
    global kill_time
    while True:
        if time.time() > kill_time:
            solenoid.off()
        time.sleep(1.0)
kill_time = 0.0
t = threading.Thread(target=kill_loop)
t.daemon = True
t.start()
def start_pour(amount):
    global count, count_cut_off, kill_time
    count_cut_off = amount
    count = 0
    solenoid.on()
    kill_time = time.time() + TIME_OUT
def count_pulse():
    global count, count_cut_off
    count  += 1
    if count >= count_cut_off:
        solenoid.off()
        clean.on() # run flow meter cleaning solenoid with food grade gas
        sleep(GAS_PAUSE) #keep clean mode for 2 second
        clean.off() # turn off clean mode enjoy drink


pulse.when_released = count_pulse
button_small.when_pressed = pour_small
button_medium.when_pressed = pour_medium
button_big.when_pressed = pour_big

count = 0
count_cut_off = MEASURE_MEDIUM


import tkinter as tk
root = tk.Tk()
root.wm_title('By Sukhpal Gill')
button_frame = tk.Frame(root)

button_frame.pack(fill=tk.X, side=tk.BOTTOM)

small_button = tk.Button(button_frame, text='Pour Small', command=pour_small)
medium_button = tk.Button(button_frame, text='Pour Medium', command=pour_medium)
big_button = tk.Button(button_frame, text='Pour Full Glass', command=pour_big)

button_frame.columnconfigure(0, weight=1)
button_frame.columnconfigure(1, weight=1)
button_frame.columnconfigure(2, weight=1)

small_button.grid(row=0, column=0, sticky=tk.W+tk.E)
medium_button.grid(row=0, column=1, sticky=tk.W+tk.E)
big_button.grid(row=0, column=2, sticky=tk.W+tk.E)

root.mainloop() # do this instead of the pause() used in the gpiozero code