Hi all, I have a Pico WH with the Piicodev Expansion Board and a BME280 atmospheric sensor. I’ve written a Micropython program for the Pico to get the weather data every 10 minutes and upload it to a web server that I wrote in Python which runs on my PC running Ubuntu.
The program on the Pico is saved as main.py and it runs perfectly from Thonny. If I do a soft reboot within Thonny, main.py runs automatically.
However, if I’m not using Thonny, then main.py doesn’t run - even when the Pico is using the same USB cable that is still connected to my PC. Same thing happens if I try to run the Pico from a separate USB power source - main.py does not start automatically.
Have you seen this before? Do you have any ideas? I’m wondering if the Piicodev Expansion Board has something to do with this, but I’m not sure.
Welcome to the Forum @Dean94493
I have a few ideas to help troubleshoot what might be causing the issue with main.py:
- Double check that main.py is indeed saved on the Pico. Even though Thonny might be running main.py on your Pico, the actual file might only be saved on your computer’s hard drive. Thonny will happily run the file this way, until of course you are no longer connected to the computer!
You can check it is saved on the Pico by first making the Files view is open in Thonny (View > tick ‘Files’), and then confirming the main.py file is listed under the bottom left ‘Raspberry Pi Pico’ panel:
If it’s not there, you will need to upload it via the ‘This computer’ Files panel above. Right-click the file and select “upload to /”.
- If main.py is saved to the Pico and it is still not running outside of Thonny, the next step is to isolate if the root cause is due to a software/code issue or a hardware issue.
The simplest method to rule out if it is a software or hardware issue is to save a simple ‘blink’ program as main.py onto the Pico, which blinks the onboard LED on and off (see below code example for the Pico WH). If the LED does not blink on external power then there is a definite hardware issue, however if the LED does blink on external power - then the issue likely lies within the code (although it could still be hardware related).
from machine import Pin
led = Pin("LED", Pin.OUT)
Let me know how you get on with those initial troubleshooting steps, at the very least they should start pointing you in the right direction for where to start digging deeper!
Thanks for your response. My script was definitely saved as main.py correctly, but it behaved as I described.
However, when I put a simple LED blink program into main.py, it worked correctly. And that was with the Pico attached to the Piicodev Expansion Board.
It must be something in my code, so I’ll look further. It might be that the code has some print statements to help with debugging, and without a console to display them to (like the REPL screen in thonny) then maybe they’re causing issues and the script is aborting. Not sure, but I’ll dig deeper - good to know that the Pico is ok though, and that the Piicodev board makes no difference.