Python Forum
Wine / liquor dispenser project code issue
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Wine / liquor dispenser project code issue
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Updating Code And Having Issue With Keys Xileron 8 1,132 May-25-2023, 11:14 PM
Last Post: DigiGod
  Issue in Starting Django project with Docker Prabakaran141 0 824 Sep-26-2022, 12:15 PM
Last Post: Prabakaran141
  NameError issue with daughter's newb code MrGonk 2 1,449 Sep-16-2021, 01:29 PM
Last Post: BashBedlam
  Calculator code issue using list kirt6405 4 2,252 Jun-11-2021, 10:13 PM
Last Post: topfox
  Issue with code for auto checkout nqk28703 2 2,161 Nov-01-2019, 09:33 AM
Last Post: nqk28703
  code issue sandy 1 1,748 Mar-14-2019, 07:16 PM
Last Post: micseydel
  Visual Studio Code - PEP8 Lambda Issue Qui_Ten 1 2,723 Jan-28-2019, 08:17 AM
Last Post: buran
  Issue using cv2.cv in code Huzefa95s 7 6,843 Oct-28-2018, 06:11 AM
Last Post: Huzefa95s
  Is there a more efficient way to code this project? gkiranseo 1 2,687 Sep-25-2018, 09:51 AM
Last Post: Larz60+
  Issue in my multiprocessing Python code? PrateekG 7 4,212 Jul-19-2018, 06:47 PM
Last Post: gontajones

Forum Jump:

User Panel Messages

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