From d4d6b4cb08201633655e3037bb8e971b2892a860 Mon Sep 17 00:00:00 2001 From: Tilman Date: Thu, 6 Aug 2020 18:20:42 +0000 Subject: [PATCH 1/3] garage.py interference debouncing --- garage.py | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/garage.py b/garage.py index 34d1afd..911d4e7 100644 --- a/garage.py +++ b/garage.py @@ -20,31 +20,39 @@ PIN_REMOTE = 26 PIN_LED = 11 GPIO.setmode(GPIO.BCM) -GPIO.setup(PIN_MOTOR_BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) -GPIO.setup(PIN_REMOTE_BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) +GPIO.setup(PIN_MOTOR_BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_UP) +GPIO.setup(PIN_REMOTE_BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(PIN_MOTOR, GPIO.OUT) GPIO.setup(PIN_REMOTE, GPIO.OUT) GPIO.setup(PIN_LED, GPIO.OUT) def motor_button(channel): - logging.info("trigger motor") - GPIO.output(PIN_MOTOR, GPIO.LOW) - GPIO.output(PIN_LED, GPIO.HIGH) - time.sleep(0.4) - GPIO.output(PIN_MOTOR, GPIO.HIGH) - GPIO.output(PIN_LED, GPIO.LOW) + time.sleep(0.01) # el cheapo relay module creates lots of interference, so we check again after a waiting period (see https://electronics.stackexchange.com/a/361793/253533) + if channel == 0 or GPIO.input(PIN_MOTOR_BUTTON) == False: + logging.info("trigger motor") + GPIO.output(PIN_MOTOR, GPIO.LOW) + GPIO.output(PIN_LED, GPIO.HIGH) + time.sleep(0.4) + GPIO.output(PIN_MOTOR, GPIO.HIGH) + GPIO.output(PIN_LED, GPIO.LOW) + else: + logging.info("fluke (motor button)") def remote_button(channel): - logging.info("trigger remote") - GPIO.output(PIN_REMOTE, GPIO.HIGH) - GPIO.output(PIN_LED, GPIO.HIGH) - time.sleep(0.4) - GPIO.output(PIN_REMOTE, GPIO.LOW) - GPIO.output(PIN_LED, GPIO.LOW) + time.sleep(0.01) + if channel == 0 or GPIO.input(PIN_REMOTE_BUTTON) == False: + logging.info("trigger remote") + GPIO.output(PIN_REMOTE, GPIO.HIGH) + GPIO.output(PIN_LED, GPIO.HIGH) + time.sleep(0.4) + GPIO.output(PIN_REMOTE, GPIO.LOW) + GPIO.output(PIN_LED, GPIO.LOW) + else: + logging.info("fluke (remote button)") -GPIO.add_event_detect(PIN_MOTOR_BUTTON, GPIO.RISING, callback=motor_button, bouncetime=250) -GPIO.add_event_detect(PIN_REMOTE_BUTTON, GPIO.RISING, callback=remote_button, bouncetime=250) +GPIO.add_event_detect(PIN_MOTOR_BUTTON, GPIO.FALLING, callback=motor_button, bouncetime=250) +GPIO.add_event_detect(PIN_REMOTE_BUTTON, GPIO.FALLING, callback=remote_button, bouncetime=250) GPIO.output(PIN_MOTOR, GPIO.HIGH) GPIO.output(PIN_REMOTE, GPIO.LOW) From a8535da19479a566966d6dfc7105b7ac57b1418a Mon Sep 17 00:00:00 2001 From: Tilman Date: Mon, 17 Aug 2020 10:02:21 +0000 Subject: [PATCH 2/3] Update garage.py - 0.8s impulse for remote --- garage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/garage.py b/garage.py index 911d4e7..f0e9223 100644 --- a/garage.py +++ b/garage.py @@ -42,10 +42,10 @@ def motor_button(channel): def remote_button(channel): time.sleep(0.01) if channel == 0 or GPIO.input(PIN_REMOTE_BUTTON) == False: - logging.info("trigger remote") + logging.info("trigger remote 0.8") GPIO.output(PIN_REMOTE, GPIO.HIGH) GPIO.output(PIN_LED, GPIO.HIGH) - time.sleep(0.4) + time.sleep(0.8) GPIO.output(PIN_REMOTE, GPIO.LOW) GPIO.output(PIN_LED, GPIO.LOW) else: From d736d1e4e9cea286f135bab9e65df2fe8a8ce466 Mon Sep 17 00:00:00 2001 From: Tilman Date: Wed, 26 Aug 2020 18:21:44 +0000 Subject: [PATCH 3/3] Update garage.py --- garage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/garage.py b/garage.py index f0e9223..233ebe0 100644 --- a/garage.py +++ b/garage.py @@ -37,7 +37,7 @@ def motor_button(channel): GPIO.output(PIN_MOTOR, GPIO.HIGH) GPIO.output(PIN_LED, GPIO.LOW) else: - logging.info("fluke (motor button)") + logging.info("flare (motor button)") def remote_button(channel): time.sleep(0.01) @@ -49,7 +49,7 @@ def remote_button(channel): GPIO.output(PIN_REMOTE, GPIO.LOW) GPIO.output(PIN_LED, GPIO.LOW) else: - logging.info("fluke (remote button)") + logging.info("flare (remote button)") GPIO.add_event_detect(PIN_MOTOR_BUTTON, GPIO.FALLING, callback=motor_button, bouncetime=250) GPIO.add_event_detect(PIN_REMOTE_BUTTON, GPIO.FALLING, callback=remote_button, bouncetime=250)