Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    PIN Interrupt Problem

    Scheduled Pinned Locked Moved LoPy
    3 Posts 3 Posters 2.4k Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A Offline
      avalgy
      last edited by avalgy

      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: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

      Alessio

      1 Reply Last reply Reply Quote 0
      • L Offline
        LoneTech
        last edited by

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

        1 Reply Last reply Reply Quote 0
        • J Offline
          jubbs
          last edited by jubbs

          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):
          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 time

          class Drips:
          pass

          drips = Drips()
          drips.count = 0

          def drip(p):
          drips.count+=1

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

          1 Reply Last reply Reply Quote 0

          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
          • 1 / 1
          • First post
            Last post

          Pycom on Twitter

          Pycom