Stop Crtl C keyboard interrupts?

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
superace
Posts: 10
Joined: Thu Jan 17, 2019 1:57 am

Stop Crtl C keyboard interrupts?

Post by superace » Thu Jan 17, 2019 2:13 am

Hi all,
I have searched high and low using my google skills but I fail to come up with a working solution. I need to turn off the keyboard interrupt on the RX0 pin. Today 03h will break the program. How is this done?

I am using a Nodemcu with a ESP8266 module. The solution passing -3 to the interrupt handler does nothing as far as I can tell. I am using Tera Term to verify this behaviour and Ctr C kills the execution of the main loop every time.

Any input in this is highly appreciated.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Stop Crtl C keyboard interrupts?

Post by Roberthh » Thu Jan 17, 2019 6:31 am

micropython.kbd_intr(chr) will do that. micropython.kbd_intr(chr) sets the interrupt to the character chr. micropython.kbd_intr(-1) disables keyboard interrupt, micropython.kbd_intr(3) sets it back to Ctrl-C

See also: http://docs.micropython.org/en/latest/l ... ython.html

superace
Posts: 10
Joined: Thu Jan 17, 2019 1:57 am

Re: Stop Crtl C keyboard interrupts?

Post by superace » Thu Jan 17, 2019 1:10 pm

That's exactly what I have tried, both in the boot file and main as first row but it doesn't make any difference from what I can see. -1 or 3 or any other number, tera term break will still break the running program and kick me out to repl. But ok if that's the magic bullet I will try more tomorrow. Thank you for verifiering that the method should give this result.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Stop Crtl C keyboard interrupts?

Post by Roberthh » Thu Jan 17, 2019 2:13 pm

It does only work in scripts, not in the REPL loop. During REPL mode, keyboard interrupt will always be reset to Ctrl-C. So if you make a short script like:

Code: Select all

import micropython
import time
micropython.kbd_intr(ord('q'))
while True:
    print('.', end='')
    time.sleep(0.5)
You can cause a keyboard interupt with the letter q.

P.S.: I hope the code works. I have no pyboard here for testing.

Post Reply