Is it possible to update a Python program on RasPi Pico via USB?

Thread Starter

PhilTilson

Joined Nov 29, 2009
129
There may be a very simple answer to this...!

I have a device based on a RasPi Pico running a python script. It would be very useful to be able to update the script from time to time, but the end-user will not have Thonny, nor have access to the button on the Pico.

What I really want to be able to do is to update the script via the USB port from a PC. Is such a thing possible?

I have made several searches to try to solve this and note it MAY be possible using the C SDK but that is inappropriate in this case.
 

Ya’akov

Joined Jan 27, 2019
8,529
Well, not easily but I suppose in theory you could include circuitry to have the RPi press it’s own PROG button by latching something that would time out after the reboot.
 

Thread Starter

PhilTilson

Joined Nov 29, 2009
129
Hmm - not ideal! It must be possible, because Thonny does exactly this. I can select a file, tell it to upload and there it is. I just need to know how the hell they do it!
 

Thread Starter

PhilTilson

Joined Nov 29, 2009
129
It seems that if you connect to the Pico at 1200 bps then disconnect, it will enter bootloader mode. (untested)
Sadly, I have not been able to make this happen!

Can you just be a little more specific? If I "...connect at 1200bps, then disconnect" I am no longer connected! Are you saying that, if I then reconnect (presumably still at 1200bps) I should be in bootloader mode?
 

Ya’akov

Joined Jan 27, 2019
8,529
Sadly, I have not been able to make this happen!

Can you just be a little more specific? If I "...connect at 1200bps, then disconnect" I am no longer connected! Are you saying that, if I then reconnect (presumably still at 1200bps) I should be in bootloader mode?
If it works the way I understand it (and I have not had the chance to investigate further), I would expect the Pico to so it would as a mass storage device on the connected connected computer.

I might be get a chance to test it and I can let you know.
 

Ya’akov

Joined Jan 27, 2019
8,529
OK, so I tested it and it works as expected. Connect to the Pico as a serial connection, at 1200bps, on the port presented by the on-board USB to TTL converter. Reset the connection. The Pico restarts and is mounted as a mass storage device, as if the BOOTSEL had be held down.

Pretty simple.
 

Thread Starter

PhilTilson

Joined Nov 29, 2009
129
Not sure what I am missing here, but I have tried this using both TeraTerm and PuTTY and I just cannot persuade the Pico to talk at 1200bd! Whatever settings I enter in either terminal emulator, it seems determined to communicate at 115200bd - which is why, presumably, I can't get it into BOOTSEL mode as you suggest! Where am I going wrong here??
 

Ya’akov

Joined Jan 27, 2019
8,529
Not sure what I am missing here, but I have tried this using both TeraTerm and PuTTY and I just cannot persuade the Pico to talk at 1200bd! Whatever settings I enter in either terminal emulator, it seems determined to communicate at 115200bd - which is why, presumably, I can't get it into BOOTSEL mode as you suggest! Where am I going wrong here??
I wish you were not using Windows, it would be easier. If you have access to a Linux or MacOS box, you can just type:

stty -clocal -f /dev/<name of serial device> 1200
At a shell prompt to kick it. But Windows... hmm... Try the Windows mode command, maybe like this:

mode com<N> baud=1200
Before using your terminal program. mode com[I]n[/I] /status will show you if it had an effect. I am not sure this will work, but it might. You could also try using that line, then:

echo com<N> "Hello nurse!"
To send something to the RPi at 1200 which might persuade it to restart in mass storage mode.

I can tell you that it is very reliable about switching here, when I use the stty method, so I am certain you can make it work. One last thing, I'm not a Python user, but it was easy to whip up a perl one-liner to accomplish the same thing. I would think you could use Python and whatever the Serial Port interface module is to do it as well.
 

Thread Starter

PhilTilson

Joined Nov 29, 2009
129
Nope! Stubbornly refuses to use anything other than 115200bd, even though MODE says it has been set to 1200!
Code:
Status for device COM12:
------------------------
    Baud:            1200
    Parity:          None
    Data Bits:       8
    Stop Bits:       1
    Timeout:         ON
    XON/XOFF:        OFF
    CTS handshaking: OFF
    DSR handshaking: OFF
    DSR sensitivity: OFF
    DTR circuit:     ON
    RTS circuit:     ON

C:\Users\phil>echo com12 "Hello nurse!"
com12 "Hello nurse!"
I think this must be something to do with Windows. I am very sketchy on Linux/Unix but it looks as though I will need to get my act together! However, if that works, I'm still in trouble as most of my end users wont be running Linux! Ho hum...
 

Ya’akov

Joined Jan 27, 2019
8,529
Well, the Python route might be an answer. You really just need a tiny C program to do this, maybe you could learn just enough to write one. It should be trivial.
 

Ya’akov

Joined Jan 27, 2019
8,529
Oh! My bad:

echo com<N> "Hello nurse!" should have a redirect! Like echo com<N> > "Hello nurse!"

Without the redirect you are just writing to STDOUT.
 
Top