micropythonrp2040

How to make a script run on startup?


On an Elecfreaks Pico:ed I'm able to write and test MicroPython scripts using Thonny, but how to make it run on startup (when pressing the RESET button)?

How can I do that for other Raspberry Pi Pico based boards? Does it have to be given a specific file name?


Solution

  • On ESP-32 and ESP-8266 as in some others you'll see that you can find two files after installing MicroPython:

    Inside boot you can type "import somepackage" and make it run in the boot in the order that you call it, or even run some code.

    On Raspberry Pico MicroPython version, this boot.py doesn't exist when fresh installed, nor main.py.

    Both should work just fine as you can find them in the port code:

    ESP32: https://github.com/micropython/micropython/blob/master/ports/esp32/main.c#L140

    RP2: https://github.com/micropython/micropython/blob/master/ports/rp2/main.c#L180

    But be aware that other custom images can change that! For example, on Pimoroni port, the boot.py doesn't work because it is already utilized by them in another way, but main.py does.

    Some other references: