0

I just started programming in Python and I have a little problem.

I want to create a simple application based on YF-S201 (flow sensor) and DS18B20 (1wire thermometer).

My problem is in the "loop". The program works correctly, at first: it counts impulses from the "flow sensor" and when elapsed time = 10s it uses the LCD to show the temperature and flow on the LCD.

After this the program does nothing. I don't know why. Maybe I forgot about something?

#!/usr/bin/env python

from RPLCD import CharLCD, cleared, cursor

import RPi.GPIO as GPIO
import time, sys


FLOW_SENSOR = 24

GPIO.setmode(GPIO.BCM)
GPIO.setup(FLOW_SENSOR, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)

global count
count = 0
global time_start
global tdelta
time_start= time.time()
tdelta = 0


def countPulse(channel):
    global count
    global time_start
    count = count+1
    tdelta = (time.time() - time_start)    
    if tdelta  >= 10.0:
        tempfile = open("/sys/bus/w1/devices/28-000004b18235/w1_slave")       #okreslenie czujnika
        thetext = tempfile.read()  #otwarcie - pobranie danych
        tempfile.close()
        tempdata = thetext.split("\n")[1].split(" ")[9] #podzial na 
        temperatura = float(tempdata[2:])  #obciecie dwoch 
        temperatura = temperatura / 1000  #podzial przez 1000   

        temperatura = str(temperatura)    
        flow=int(count / 75)
        flow=str(flow)
        count = 0
        #use LCD
        lcd = CharLCD()
        with cleared(lcd):
            lcd.write_string(temperatura)
            lcd.write_string(u' st. C')
            lcd.cursor_pos=(1,0)
            lcd.write_string(flow +u' l/min')
        #take  actual time
        tdelta=0
        time_start = time.time()

GPIO.add_event_detect(FLOW_SENSOR, GPIO.RISING, callback=countPulse)


while True:
    try:
        time.sleep(1)
    except KeyboardInterrupt:
        print '\ncaught keyboard interrupt!, bye'
        GPIO.cleanup()
        sys.exit()

migrated from stackoverflow.com Nov 24 '15 at 19:20

This question came from our site for professional and enthusiast programmers.

  • I resolve problem. – HusArK Nov 8 '15 at 17:37
  • The problem was in module LCD - changing GPIO.setmode to BOARD – HusArK Nov 8 '15 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy