• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Raspberry pi PICO can not stop main.py

Q&A Forum › Category: Raspberry Pi › Raspberry pi PICO can not stop main.py
0 Vote Up Vote Down
Dick van de Wetering asked 8 months ago

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

Question Tags: main.py, Pico, Python
2 Answers
0 Vote Up Vote Down
Dick van de Wetering answered 8 months ago

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.

0 Vote Up Vote Down
Sara Santos Staff answered 8 months ago

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

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.