1

When I include a while True: in my main.py I can no longer overwrite it and upload a new version.

Many beginner guides and tutorials, eg: this one and this one, use while True. So I guess it should be possible.

I have tried using Thonny and ampy for uploading (overwriting) main.py while the board was running the endless loop.

My current workaround is connecting to the REPL using picocom and deleting the file using os.remove.

Micropython version: esp8266-20210618-v1.16

NB. I know that timers can mitigate the need for an endless loop.

Sander van Leeuwen
  • 2,963
  • 2
  • 22
  • 31
  • If you don't connect before the while starts it will block and you can't connect. You could put a short sleep before the while loop or just don't use a main.py. My work is in constant development, and always tethered to the computer so, I just don't use a main. Instead I have a custom shell script that starts the REPL after scripts are uploaded, and it injects an `import` line that kicks off my otherly named main file. – OneMadGypsy Jun 23 '21 at 00:51

1 Answers1

0

Take a look at the very first example to which you linked, which describes exactly your current situation after introducing the while true loop:

You might be worried to see the >>> REPL prompt never appears again and you can't enter code. Remember this is because MicroPython can only do one thing at a time and the infinite loop means the board is busy blinking the LED.

Luckily you can tell the board to stop whatever it's doing and return back to the REPL prompt. Press the Ctrl-c key on your keyboard and you should see the code stop with a KeyboardInterrupt error like this:

When you have an infinite loop running, nothing else is able to run. You need to exit the loop if you expect to be able to interact with the REPL (which is exactly what ampy does, for example).

larsks
  • 277,717
  • 41
  • 399
  • 399
  • Thanks for your answer. I got it to work using Thonny, indeed by pressing ctrl+c as soon as it's running the while loop. Which then shows the REPL, after which I can read and write files again (within Thonny). With `ampy` I still don't get it to 'put' when in the while loop. It's then waiting, and when I press ctrl+c it's canceling the 'put' cmd. – Sander van Leeuwen Jul 05 '21 at 09:20