logo elektroda
logo elektroda
X
logo elektroda

[Solved] Errors when uploading a program with interrupts to the ESP8266 in MicroPython

mlp99 636 1
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 17724890
    mlp99
    Level 9  
    I have a problem uploading a program to the ESP8266. I have written a program in micropython. Everything is ok until I don't use interrupts, then errors pop up when trying to upload the program:
    Code: Text
    Log in, to see the code
    .

    My program looks like this:
    from utime import sleep_ms
    from machine import Timer
    import micropython
    
    micropython.alloc_emergency_exception_buf(100)
    
    [inContentAd]
    
    timer1s = Timer(-1)
    timer1s.init(mode=Timer.PERIODIC, period=500, callback=lambda t: print("INTERRUPT"))
    
    
    def main():
    
        while True:
            print("MAIN")
            sleep_ms(300)
    
    
    if __name__ == '__main__':
        main()
    .

    In general it looks like these interrupts are blocking the upload of the software. They interrupt it, because when I turn off the timer or set the period to about 15 seconds, the program uploads. For now, the way I cope is that every time I erase the e esp memory with esptool and re-upload the NodeMCU, but it takes a long time and is annoying.
    I use pycharm and the Micropytchon plugin, but it is unlikely to make a difference.
  • ADVERTISEMENT
  • #2 17725283
    mlp99
    Level 9  
    I have a problem uploading a program to the ESP8266. I have written a program in micropython. Everything is ok until I don't use interrupts, then errors pop up when trying to upload the program:
    Code: Text
    Log in, to see the code
    .

    My program looks like this:
    from utime import sleep_ms
    from machine import Timer
    import micropython
    
    micropython.alloc_emergency_exception_buf(100)
    
    timer1s = Timer(-1)
    timer1s.init(mode=Timer.PERIODIC, period=500, callback=lambda t: print("INTERRUPT"))
    
    
    def main():
    
        while True:
            print("MAIN")
            sleep_ms(300)
    
    
    if __name__ == '__main__':
        main()
    .

    Overall, it looks like these interrupts are blocking the upload of the software. They interrupt it, because when I turn off the timer, or set the period to about 15 seconds, the program uploads. For now, the way I cope is that every time I erase the e esp memory with esptool and re-upload the NodeMCU, but it takes a long time and is annoying.
    I use pycharm and the Micropytchon plugin, but it is unlikely to make a difference.

    Added after 1 [hour] 35 [minutes]: .

    The simplest and most effective solution is to de-initialise the timer while handling the KeyboardInterrupt exception, which can be triggered by firing the REPL and pressing CTRL+C.

    def main():
        try:
            while True:
                print("MAIN")
        except KeyboardInterrupt:
            timer1s.deinit()
    .
ADVERTISEMENT