Python Forum
Pressure monitor for keg fridge
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pressure monitor for keg fridge
#1
I just put this together and it seems to be working well. I don't have the LEDs connected yet, but the "print" function proves they will with correct connections. I may add a few more LEDs for the scale between 11 and 13.5, each with a .5 range. I can do that just fine. I'm posting here to see if there are any wasted lines of code, can this be cleaned up?

import time
from time import sleep
from datetime import datetime
import Adafruit_ADS1x15
adc = Adafruit_ADS1x15.ADS1115(address=0x48, busnum=1)
from gpiozero import LED

GAIN = 2/3
LEDHIGH = LED(21)
LEDNORM = LED(26)
LEDLOW = LED(16)


while 1:
    value = [0] 
    value[0] = adc.read_adc(0, gain=GAIN)
    volts = value[0]/32767.0 * 6.144    
    now = datetime.now()
    current_time = now.strftime("%H:%M:%S")
    manifoldraw = volts / .145
    manifold = str(round(manifoldraw, 2))

    print(current_time, "  ", manifold)
    
    if 12.25 <= manifoldraw <= 12.75:
        LEDNORM.on()
        print("pressure OK")
    else:
        LEDNORM.off()
        #print("off")
        
    if 0 <= manifoldraw <=12.24:
        LEDLOW.on()
        print("pressure LOW")
    else:
        LEDLOW.off()
        
    if 12.76 <= manifoldraw <= 99999:
        LEDHIGH.on()
        print("pressure HIGH")
    else:
        LEDHIGH.off()

    sleep(1)
    
Basic function in this configuration is that I will have one LED on when the pressure is normal, between 12.25 and 12.75. Other LEDs would indicate when I am higher than 12.76 or lower than 12.24. I intend to add a requests.post that hits a URL that sends a message to my Androids if pressures get above 15 or below 10. Optimum pressure on this application is 12.5. It is for the CO2 manifold for my keg fridge, so pressure is critical to preserve optimum carbonation levels of my homebrew!
Reply
#2
One thing that I would do is create a timer event, rather than poll time.
This will free up the processor so other things can be done (if needed) while waiting for an event.

Try running this snippet:

example using threaded timer:
import time, threading


def threaded_timer(delay=1):
    print(f"In timer loop: {time.ctime()}")
    threading.Timer(delay, threaded_timer).start()

# wake up after 6 seconds (can use decimal here for times less than 1 sec)
threaded_timer(delay=4)

print('Do something while waiting for timer')
time.sleep(1)
print('Do something else while waiting for timer')
Notice that timer runs independently from other code.
Output:
In timer loop: Wed Dec 2 06:42:13 2020 Do something while waiting for timer Do something else while waiting for timer In timer loop: Wed Dec 2 06:42:17 2020 In timer loop: Wed Dec 2 06:42:18 2020 In timer loop: Wed Dec 2 06:42:19 2020 In timer loop: Wed Dec 2 06:42:20 2020 In timer loop: Wed Dec 2 06:42:21 2020 ...
j.crater likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Better Way to Monitor Time Request. bill_z 2 2,093 Oct-17-2020, 04:36 PM
Last Post: ndc85430

Forum Jump:

User Panel Messages

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