PIN Interrupt Problem
-
Re: IRQ Code causes LoPy reset every time - any ideas please?
I Have a similar problem. This is my simple code:
def button_handler(pin):
print('button pressed')p_in = Pin('P10', mode=Pin.IN, pull=Pin.PULL_UP)
p_in.irq(trigger=Pin.IRQ_RISING, handler=button_handler)This is the shell (USB) message:
MicroPython 333b92c on 2016-10-26; LoPy with ESP32
Type "help()" for more information.button pressed
Guru Meditation Error of type StoreProhibited occurred on core 0. Exception was unhandled.
Register dump:
PC : 4012668c PS : 00060830 A0 : 8011f4ea A1 : 3ffdc420
A2 : 00000002 A3 : 00000002 A4 : 3ffd24f4 A5 : 3ffd24dc
A6 : 3ffd24dc A7 : 3ffd24dc A8 : 00000000 A9 : 00000000
A10 : 3ffd24dc A11 : 3ffd24dc A12 : 00000004 A13 : 00000002
A14 : 3ffdbd1c A15 : 3ffdbce4 SAR : 00000014 EXCCAUSE: 0000001d
EXCVADDR: 00000023 LBEG : 00000000 LEND : 00000000 LCOUNT : 00000000
Rebooting...
ets Jun 8 2016 00:22:57rst:0x3 (SW_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0x00I think about some problem about stack handler.
Maybe do I have to define a memory space? I haven't found nothing in the documentation.Thank you
Alessio
-
As indicated in the MicroPython rules for interrupt handlers, printing from interrupt handlers is generally unsafe.
-
Here is some example code that worked for me working with the expansion board. If this causes an error for you I would try the latest firmware. I am on 9.2.b2.
Another trap for young players is that you cannot reference a variable in the global space directly from an interrupt callback so you need to create a class. The second example is how to get that working.
Example 1
from machine import Pin
import timeled = Pin('G16', mode=Pin.OUT)
def drip(p):
led.toggle()
print('pin change', p)button = Pin('G17', mode=Pin.IN, pull=Pin.PULL_UP)
button.irq(trigger=Pin.IRQ_RISING, handler=drip)Example 2
from machine import Pin
import timeclass Drips:
passdrips = Drips()
drips.count = 0def drip(p):
drips.count+=1button = Pin('G17', mode=Pin.IN, pull=Pin.PULL_UP)
button.irq(trigger=Pin.IRQ_RISING, handler=drip)
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login