Page 1 of 1

Cannot Unstuck Raspbery Pi Pico

Posted: Sun Sep 19, 2021 3:10 pm
by cnmcdee
Working (runs a led-blink) and something else : and USB connection dmesg -w output:

Code: Select all

[ 3497.923509] usb 2-1: new full-speed USB device number 50 using xhci_hcd
[ 3498.050990] usb 2-1: New USB device found, idVendor=2e8a, idProduct=0005, bcdDevice= 1.00
[ 3498.050993] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 3498.050995] usb 2-1: Product: Board in FS mode
[ 3498.050996] usb 2-1: Manufacturer: MicroPython
[ 3498.050998] usb 2-1: SerialNumber: e6609103dr955539
[ 3498.052671] cdc_acm 2-1:1.0: ttyACM0: USB ACM device
Thonny cannot get it, neither can screen /dev/ttyACM0 115200.

Not seeing any device block showing up to replace / reset the UFI file.

Tried holding reset while cycling USB connection. Nope.

Question is the on-board reset button exactly the same as the RUN pin to GND reset button?

Re: Cannot Unstuck Raspbery Pi Pico

Posted: Sun Sep 19, 2021 4:25 pm
by cnmcdee
I found the solution and unfortunately that Pico is forever stuck in it's own little world whatever it is doing.

When you are developing - never name your file main.py or boot.py

boot.py loads first and then main.py loads and runs second.

If you put something highly aggressive (like toggling a pin every microsecond) inside either of these files it will pretty much 'lock-up' the device as these aggressive programs will be re-activated automatically.

Name your developmental file something else, and upon a reboot that program will not execute because it is not one of the two default names and you will have full function of the device back. You can still call that program from inside Thonny or your developmental set. Then you can let Thonny call it as you desire.

Once you have it perfected, then give it the generic call name.

Re: Cannot Unstuck Raspbery Pi Pico

Posted: Sun Sep 19, 2021 4:59 pm
by ex_piro

Re: Cannot Unstuck Raspbery Pi Pico

Posted: Mon Oct 04, 2021 6:11 am
by djpearson
Perhaps a related question....
I just received my pi pico and successfully ran my simple blink script below using Thonny. Should be a no-brainer, right? Well it worked and then I decided to save it to the pico as main.py Of course it works also when the USB was disconnected and reconnected, as I had planned.

What surprised me is that I could not subsequently stop the script from running using Thonny. I knew the script was running on the pico but apparently Thonny could not interrupt it? I tried various sequences of bringing up Thonny first, then plugging in the USB cable and vice-versa, but all attempts resulted in the pico continuing to run the simple script. I tried STOP, I tried cntl-c, etc but the LED kept blinking.

I finally decided to go into bootloader mode and use the flash_nuke.uf2 to erase all the pico files and then used Thonny to restore the latest .uf2 file.

Now I am hesitant to ever have a file named main.py on the pico unless I intend that to be the final configuration! Does anyone know of a way to terminate a main.py script that exists on Pico from the PC (Windows 10 in my case)? I am just surprised that stop or cntrl-c didn't stop the execution within Thonny.

Code: Select all

import machine
import utime
led_onboard = machine.Pin(25, machine.Pin.OUT)


while True:
    led_onboard.toggle()
    utime.sleep(3)
    

Re: Cannot Unstuck Raspbery Pi Pico

Posted: Mon Oct 04, 2021 7:09 am
by Roberthh
You should be able to stop that little script with Ctr-C. So maybe it's Thonny not being able to cope with that situation. Maybe you should also put a simple terminal emulator to your tool box, which does not try to do more than to connect. Depending on the PC operating system that could be Putty or TeraTerm for Windows, screen for OS X, picocom or tio for Linux.
Besides that, it is a common practice to put into main.py just some start-up and configuration code, and start in main.py your application with import.

Re: Cannot Unstuck Raspbery Pi Pico

Posted: Mon Oct 04, 2021 6:23 pm
by hippy
djpearson wrote:
Mon Oct 04, 2021 6:11 am
I finally decided to go into bootloader mode and use the flash_nuke.uf2 to erase all the pico files and then used Thonny to restore the latest .uf2 file.
This is a slightly less drastic method than nuking all files, removes only "main.py", actually renames it -

https://www.raspberrypi.org/forums/view ... p?t=305432

Re: Cannot Unstuck Raspbery Pi Pico

Posted: Mon Oct 04, 2021 6:55 pm
by djpearson
I did a bit more rework on this and have a solution now. Thought I would document it here. Just FYI, I tweaked the code to produce a print output:

Code: Select all

import machine
import time
led_onboard = machine.Pin(25, machine.Pin.OUT)


while True:
    led_onboard.toggle()
    current = time.time()
    time.sleep(3.123)
    now = time.time()
    print("Current time = {}. Elapsed = {:10.3f}".format(current,now-current))
    /code]

OBSERVATIONS: 
1. If I plug in the pico, and then start Thonny, the printout appears in the REPL.  If I issue a STOP command, the printout stops but the pico continues to run its program.   
2. If I then unplug the pico, and replug it in (while Thonny is still up and running), then the pico app continues to run but produces no printout. However, I am able to stop the app using the STOP command.   

CONCLUSION:  
I just need to make sure that Thonny is up and running when I attach the pico,  then I can stop the app and perform whatever else I plan to do. 

Also, I am seeing something odd - requires more work on my part: If one runs the script above, the delta time (now minus current) is always being shown as 3.000 (and occasionally jumps to 4.000).  I expected an output of 3.123 +/- a few milliseconds?   With Arduino, I was used to the millis() function.   I also tried time.perf_counter() and time.clock() but neither seem to be supported by the pico currently.