In my series on the PiHut Maker Advent Calendar, I posed a couple of questions:
- how do you move from a wobbly breadboard to something more permanent?
- How do you run code without having the Pico tethered to a laptop running Thonny?
I have, at least, now worked out how you do the latter of these two and I will explain how below.
In order to get a script to run on start-up you need to save a file called “main.py” to your Pico device. To do that I have included steps for this using Thonny. Firstly, make sure that your Pico is connected and that you have loaded the file that you want to use as the routine on your Pico.
Next, choose File > Save As from the menu (if you don’t see this option see the instruction at the bottom of this page).
You will now be asked where you want to save your file. Select Raspberry Pi Pico:
You will now be shown a dialog box with the list of files already loaded on your Pico (there may be none). As the file name enter “main.py” and press the OK button.
And, that’s it. When you next restart your Pico the main.py file will be run and carry out whatever you have set it to do – all without the need for your computer to be connected.
NOTE: If you don’t see the Save As option in Thonny open the options page and on the General tab change the UI mode to “expert”. Restart Thonny and you’ll be good to go!