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.
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).