• Hello,
    I was wondering if there were any plans to implement the micropython.schedule() method on pycom port of micropython. The ability to have it automatically comeback to do some operations that require object creation or messing with the heap soon after an interrupt handler is quite nice rather than having to have my main loop constantly checking to follow up on interrupt handlers.
    This page details some of its uses and advantages quite nicely: https://docs.micropython.org/en/latest/reference/isr_rules.html

    Alternatively are there any other suggestions for how to handle a situation where based on an interrupt I need to do some object creation and/or memory allocation? I thought of using the Alarm subclass of timer but everything I can find says to treat it like an interrupt handler with the same limitations. Any ideas would be welcome.

  • @louis-stromeyer A pin callback is a scheduled function too. Whenever an interrupt happens, the information about the handler is pushed to a queue and the ISR itself terminated. The queue is processed by a separate MicroPython thread.
    There exists cases where a c-code pin interrupt handler is immediately called. But that happens only internally by the LoRa and Sigfox firmware and is not exposed to user Python code.

  • @robert-hh Thanks for the information. Sorry missed the note in the docs. Found it now that I went looking

  • @louis-stromeyer Actually in this port Interrupt works like you need it. Whenever an Interrupt happens, it schedules a process for starting ASAP. There you have the full set of Python available, including allocation of objects. The drawback of that approach is a somewhat unpredictable interrupt response time between a few µs up to one ms.
    So for your purpose you should be able to use a timer alarm.
    Obviously there are other approaches too. You could for instance start a thread or async task and let it sleep most of the time, until a timer alarm sets a flag to wake it up.
    The power of (Micro)Python makes one sometimes forget that the platform is still 'micro'. So you have not all features of the Language on a full blown OS available, and you have to go for alternative implementations.

Log in to reply

Pycom on Twitter