Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8015

MicroPython • Re: interrupt Pico code started by mpremote

$
0
0
I haven't figured out a way to do it using only 'mpremote' but this works ...

Code:

import timetry:    while True:        print("Tick")        time.sleep(1)except:    print("Aborted")print("Finished")

Code:

pi@Pi4B:/tmp $ mpremote connect /dev/ttyACM0 run tick.pyTickTickTick^Cpi@Pi4B:/tmp $

Code:

pi@Pi4B:/tmp $ minicom -D /dev/ttyACM0Welcome to minicom 2.8TickTickCtrl-C pressed hereAbortedFinished>
That leaves MicroPython in its Raw REPL so you need to Ctrl-B to get back to the usual '>>>' interactive REPL. You don't have to do that if you don't want to; you can still execute another 'mpremote run' with it left in the Raw REPL. Just use Ctrl-A then Ctrl-X to return to the command line prompt.

While 'mpremote run' is useful to see 'print' output from the code, you have to Ctrl-C that to get back to the command line prompt. If you don't want to have to press Ctrl-C, don't care about seeing 'print' output, you can use '--no-follow' -

Code:

pi@Pi4B:/tmp $ mpremote connect /dev/ttyACM0 run --no-follow tick.pypi@Pi4B:/tmp $
So the issue appears to be how to send a Ctrl-C to interrupt the running code using 'mpremote'. It can be done using a Python program but I'll have to do some more playing to figure out if it can be done and how to do it with 'mpremote'.

An alternative to using 'minicom' is 'mpremote resume' ...

Code:

pi@Pi4B:/tmp $ mpremote connect /dev/ttyACM0 resumeConnected to MicroPython at /dev/ttyACM0Use Ctrl-] or Ctrl-x to exit this shellTickTickCtrl-C pressed hereAbortedFinished>Ctrl-X pressed herepi@Pi4B:/tmp $

Statistics: Posted by hippy — Tue Apr 08, 2025 12:37 pm



Viewing all articles
Browse latest Browse all 8015

Trending Articles