I have loaded a main.py programm in the Pico that has a mistake, I can not stop the program with ctrl-C or the stop button in Thonny. The programm keeps running. Is there a way to interrupt the programm ?
Code:
from time import sleep
from machine import Pin, UART
import time
uart = UART(0,1200)
uart.init(baudrate=1200, tx=Pin(0), rx= Pin(1), bits=8, parity=None, stop=1, invert=UART.INV_TX) # init with given baudrate
code=0
# Main loop to listen for connections
while True:
try:
code=code+2;
if code>255 :
code=0
buf1=(code).to_bytes(1,’little’)
print(code,” “,buf1)
uart.write(buf1) # write the 1 byte
sleep(0.2)
except KeyboardInterrupt:
print(‘Server stopped by user.’)
The solution is to remove the main.py from the pico, pressing boot button and connect power, than using flush.nuk.uf2 to clean the pico. After that install the RPI-PICO….. . uf2.
After this action all programs on the Pico are gone! Also main.py and you can start using it again.
Hi.
Alternatively, you can try to press the BOOT button while clicking on the stop button on the IDE at the same time.
The problem is that that main.py code is running a while loop quite fast, so it is difficult to catch the pico out of that loop to establish a connection.
Regards,
Sara