Page 1 of 1

Debouncing in IRQ

Posted: Tue Mar 31, 2020 4:36 pm
by Armen
Hello MicroPython lovers
I try resolve subject problem from
viewtopic.php?t=1938
(special thanks from dhylands for this useful post)
Who can help me for change IRQ handler to resolve this problem in this example
http://docs.micropython.org/en/v1.9.3/e ... /pins.html
Thanks Armen

Code: Select all

def callback(p):
  print('pin change', p)
  print(led.value())

from machine import Pin
from time import sleep
p0 = Pin(12, Pin.IN)
p2 = Pin(4, Pin.IN)
led = Pin(14, Pin.OUT)

p0.irq(trigger=Pin.IRQ_FALLING, handler=callback)
p2.irq(trigger=Pin.IRQ_RISING | Pin.IRQ_FALLING, handler=callback)

while True:
  led.value(not led.value())
  sleep(0.5)

Re: Debouncing in IRQ

Posted: Tue Mar 31, 2020 10:23 pm
by jimmo
Sorry I'm not sure I understand your question. What do you want to change in the IRQ handler?

You asked in the other thread about cancelling the IRQ handler. You can put that line inside the "callback" function.

Code: Select all

def callback(p):
  print('pin change', p)
  print(led.value())
  # Disable the IRQ.
  p0.irq(handler=None)
  # Now start a timer as explained in the other thread. When the timer finishes, check the pin state and re-enable the IRQ.

p0 = Pin(12, Pin.IN)
p0.irq(trigger=Pin.IRQ_FALLING, handler=callback)
 

Re: Debouncing in IRQ

Posted: Wed Apr 01, 2020 8:48 am
by pythoncoder
Please see my suggestion here.

Re: Debouncing in IRQ

Posted: Mon Apr 06, 2020 9:32 am
by Armen
pythoncoder wrote:
Wed Apr 01, 2020 8:48 am
Please see my suggestion here.
OK, I'll try to learn it from
https://github.com/peterhinch/micropyth ... DRIVERS.md
and test on ESP8266 - ESP01
Thank you for send post to guide.
Armen

Re: Debouncing in IRQ

Posted: Sun Apr 12, 2020 2:51 pm
by Armen
jimmo wrote:
Tue Mar 31, 2020 10:23 pm
Sorry I'm not sure I understand your question. What do you want to change in the IRQ handler?

You asked in the other thread about cancelling the IRQ handler. You can put that line inside the "callback" function.

Code: Select all

def callback(p):
  print('pin change', p)
  print(led.value())
  # Disable the IRQ.
  p0.irq(handler=None)
  # Now start a timer as explained in the other thread. When the timer finishes, check the pin state and re-enable the IRQ.

p0 = Pin(12, Pin.IN)
p0.irq(trigger=Pin.IRQ_FALLING, handler=callback)
 
Thank you, I'll try use it in my program.
I want hear beep from buzzer when push key . but when I send +vcc to buzzer it's have a different sound because time of 0 to 1 is not fix and every time changed. so I need use timer (or any method) to set fix time (200 ms) for sound output.

Re: Debouncing in IRQ

Posted: Tue Apr 14, 2020 1:54 am
by jimmo
Armen wrote:
Sun Apr 12, 2020 2:51 pm
I want hear beep from buzzer when push key . but when I send +vcc to buzzer it's have a different sound because time of 0 to 1 is not fix and every time changed. so I need use timer (or any method) to set fix time (200 ms) for sound output.
So what you want is when a button is pushed, to turn on a different pin for exactly 200ms ?

Re: Debouncing in IRQ

Posted: Sun Apr 19, 2020 3:01 pm
by Armen
Hi Jimmo
I want select set-point for one-wire, every time push button select array number in loop and hear stable beep.
every time beep time changed :?
Thanks
BTW: I use ESP-01 (2M) with extended pins
https://www.reboot.ms/vd/esp8266_extragpio2.jpg