Debouncing in IRQ

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
Armen
Posts: 8
Joined: Tue Mar 24, 2020 3:11 pm

Debouncing in IRQ

Post by Armen » Tue Mar 31, 2020 4:36 pm

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)

User avatar
jimmo
Posts: 2262
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Debouncing in IRQ

Post by jimmo » 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)
 

User avatar
pythoncoder
Posts: 5068
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Debouncing in IRQ

Post by pythoncoder » Wed Apr 01, 2020 8:48 am

Please see my suggestion here.
Peter Hinch

Armen
Posts: 8
Joined: Tue Mar 24, 2020 3:11 pm

Re: Debouncing in IRQ

Post by Armen » Mon Apr 06, 2020 9:32 am

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

Armen
Posts: 8
Joined: Tue Mar 24, 2020 3:11 pm

Re: Debouncing in IRQ

Post by Armen » Sun Apr 12, 2020 2:51 pm

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.

User avatar
jimmo
Posts: 2262
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Debouncing in IRQ

Post by jimmo » Tue Apr 14, 2020 1:54 am

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 ?

Armen
Posts: 8
Joined: Tue Mar 24, 2020 3:11 pm

Re: Debouncing in IRQ

Post by Armen » Sun Apr 19, 2020 3:01 pm

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

Post Reply