I'm trying to prototype a script for a future controller for my house's gate. I have reed switches that I want to wire into the ESP8266 to be able to tell whether the gate is open/opening/closed/closing. I saw that MicroPython supports IRQ thus I tried implementing that originally on pins 4 and 5 which didn't work and made me waste a few hours trying to debug it. The only pins that I'm able to use IRQ reliably on are 0 and 2. I have a Lolin v3 board with the latest firmware. Any pointers?
def closedCallback(_): print('closedCallback called') # this never appears in the serial console when repeatedly jumping pin D1/GPIO5 to GND
closedPin = Pin(5, Pin.IN)
closedPin.irq(trigger=Pin.IRQ_RISING | Pin.IRQ_FALLING, handler=lambda p: micropython.schedule(closedCallback, 0))
Can't use IRQ on any pins other than 0 & 2
Can't use IRQ on any pins other than 0 & 2
Last edited by Scarsz on Sat Nov 03, 2018 7:51 pm, edited 2 times in total.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Can't use IRQ on any pins other than 0 & 2
I have an application which has an IRQ on pin 5 which works correctly. This is on the reference board. Have you ensured that the pin is pulled up? Pins 0 and 2 have internal pullups (on the reference board) which may explain your results.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Can't use IRQ on any pins other than 0 & 2
Ah alright, that makes sense. I'm still decently new to using micro-controllers for little projects. What resistance would you suggest I buy a strip of for usage as pull-ups? Would 5k do the trick nicely?
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Can't use IRQ on any pins other than 0 & 2
Yes 5KΩ or thereabouts is fine - the resistor should, of course, be to the 3.3V supply. But you can also define Pin objects with an internal pull-up, see the docs. The internal resistor has a higher value, but will work OK for switches connected to the board by reasonably short wires.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.