2

I've searched and not found an answer.. I'm proficient in C and Micro-python and developing and running programs is easy enough.

However I can't figure out how I install a program I've written to the Pico so that when I supply it purely power it runs?

With ESP32 devices I would normally flash the program to NVMe ram and configure uboot to run it.

5 Answers 5

7

Using Thonny save your MicroPython file to the pico as a file called main.py

Next time you power on the Pico your program should autostart.

See section 4.1.1:

https://datasheets.raspberrypi.org/pico/raspberry-pi-pico-python-sdk.pdf

5

Or, if you don't want to use Thonny (I prefer to choose my own development environment), you can use ampy, a command-line tool for micropython boards.

Example usage:

ampy -p /dev/ttyACM0 put main.py

Note that to auto-run, your Python file needs to be called main.py.

3
  • Thanks I use C normally.. Buy I've been playing with micro python on the nano so its nice to know how to auto start it. Commented Mar 1, 2021 at 19:07
  • 1
    @SimonBanks For C, I think you just build a UF2 binary, and drag that onto the Pico after booting it in programming mode? I haven't tried C on the Pico yet myself, but I think that's the method.
    – marcelm
    Commented Mar 1, 2021 at 20:48
  • @SimonBanks By the way, the Pico also has a single-wire debugging interface (the 3 pads on the short side). I think you can also program it over that interface, but I really haven't researched that yet :)
    – marcelm
    Commented Mar 2, 2021 at 14:53
2

I met only with failure to have main.py run on the Pico at boot until I realized the file had been saved on the Pico through Thonny WITHOUT the .py extension. Ridiculous, but it may explain why many have had the same problem.

1

In order to upload a Python script with ampy or rshell as mentioned in the answers above, one may need to add itself to dialout group to be able to upload without sudo. Note re-login is needed for the group change to take effect

sudo usermod -aG dialout $USER

By default on my Ubuntu, Pico's serial port is owned by root user and dialout group so an ordinal user cannot access it

ls -l /dev/ttyACM1
crw-rw---- 1 root dialout 166, 1 Mar  7 09:57 /dev/ttyACM1
0

Or with rshell instead of ampy:

python3 -m pip install --user rshell
rshell -p /dev/ttyACM0 --buffer-size 512 cp blink.py /pyboard/main.py

See also: https://stackoverflow.com/questions/66183596/how-can-you-make-a-micropython-program-on-a-raspberry-pi-pico-autorun/74078142#74078142

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.