Suner
Posts: 3
Joined: Tue Mar 26, 2019 7:04 pm

Python Help - "trigger" GPIOZERO only at "button push"

Tue Mar 26, 2019 7:11 pm

Hi,
I need some help with my python-gpiozero combination.
I build an Script and installation to get the impulses of my gas meter "Pipersberg G4 RF1c"
I am using a proximity sensor to manage this. It works quite good, but there is ONE condition, everyhing collapses..:
My gas meters gives a impuls every 0,001 kbm of gas consumed. My sensor recognized this and print out a specified string. It works good, but if the gas meters "stucks" at the point the sensor get the impuls, the sensor stays active, so the Script is activated again and again and again as long as the gas meters continues..

Code: Select all

from gpiozero import Button
import datetime
import time
from time import sleep

from time import sleep

button = Button(4)

while True:
        button.wait_for_press()
        datetime.datetime.now().strftime("%a, %d %B %Y %H:%M:%S")
        print(datetime.datetime.now())
        sleep(2)
        print("The button was pressed!")
Anyone has an idea how to catch this issue??

Thanks in advance, Regards

Suner..

ps: sorry for possible bad english

keithellis
Posts: 142
Joined: Thu Dec 12, 2013 10:39 pm
Location: Suffolk, UK
Contact: Website

Re: Python Help - "trigger" GPIOZERO only at "button push"

Tue Mar 26, 2019 10:02 pm

Maybe you could use the

Code: Select all

when_released
method. See the documentation here https://gpiozero.readthedocs.io/en/stab ... ar-classes

Regards,
Keith.

Suner
Posts: 3
Joined: Tue Mar 26, 2019 7:04 pm

Re: Python Help - "trigger" GPIOZERO only at "button push"

Wed Mar 27, 2019 5:08 am

Never thought about using this in my case. thanks a lot!!!
Read this in documentation but thought my usecase is a different one.
Great. I give it a try

Suner
Posts: 3
Joined: Tue Mar 26, 2019 7:04 pm

Re: Python Help - "trigger" GPIOZERO only at "button push"

Wed Mar 27, 2019 5:13 am

I changed it this way.
We will see during the day:-) (dont want destroy my setup to reproducing :oops: )

Code: Select all

while True:
        button.wait_for_press()
        datetime.datetime.now().strftime("%a, %d %B %Y %H:%M:%S")
        print(datetime.datetime.now())
        sleep(5)
        print("UND wieder ein m3 mehr Gas verbraucht - Script ausfuehren")
        IpsRpc("IPS_RunScript", [30670])
        button.wait_for_release()

Return to “Troubleshooting”