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
    ets Jun 8 2016 00:22:57

    rst:0x3 (SW_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
    configsip: 0, SPIWP:0x00

    I 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


  • 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 time

    led = Pin('G16', mode=Pin.OUT)

    def drip(p):
    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 time

    class Drips:

    drips = Drips()
    drips.count = 0

    def drip(p):

    button = Pin('G17', mode=Pin.IN, pull=Pin.PULL_UP)
    button.irq(trigger=Pin.IRQ_RISING, handler=drip)

  • As indicated in the MicroPython rules for interrupt handlers, printing from interrupt handlers is generally unsafe.


Hello World?

Pylife on Kickstarter - November 2018

Back Us On Kickstarter >

Pycom on Twitter