Main.py script not starting on power-on (pico)

Hi All,

I currently have a raspberry pi pico 2H and a waveshare 2.8” restouch OLED display. I have a working script that has graphics, text, and two buttons mapped to touchscreen for a simple start/stop timer. But have two problems I’m struggling with and I don’t know if they’re related:

  1. My main script works fine in Thonny and VS Code. Although, I’ve noticed that when I plug it into my laptop to code, my own script doesn’t actually run through Thonny/VSC without first running one of the demo scripts from waveshare site. It’s weird, it’s as though the demo script (or rather a script that I did not write) wakes up the pico and then I can use it as normal running mine. Ie. I open Thonny → open my script → click run and nothing happens → open demo code → click run and it works → click run on my script again and now it works.
  2. I can’t get my script to start on powerup. I’ve done the bootsel → save as main.py on pico (also tried boot.py) → unplug and plug into PC or wall socket USB and nothing. Have UF2 file, tried redownloading and doing it again. Still nothing.

Obviously pointing to an issue with my code, and I’m sure I’m missing something but I am finding the first problem kind of strange since my script is still running, it just needs a weird wakeup first.

Hey there, Leigh,

That is some very strange behaviour from the Pico. I’m leaning to the idea that there is either something weird with your imports or else the directory structure just needs a little tidy, but that’s just a theory at this point.

Could you post a picture of your Pico’s directory structure, upload a copy of your main.py, and confirm which of the Waveshare demo scripts you are using as your library.

And don’t worry, coding is 90% finding issues in your code. I have wasted days of my life trying to troubleshoot what turn out to be very simple problems in my code. It happens to all of us.

Thought I would reply to say I sort of figured it out. I was missing a couple of imports (ones I wasn’t even aware I needed but I essentially copied the import list from the start of the waveshare demo codes and added it with the rest of mine). That seemed to do the trick.

I then had everything starting on powerup, but my touch buttons weren’t working! This I “fixed” with adding a bunch of sleep() in at random points. “Fixed” because it all works half the time. Sometimes it stops again, which I think is potentially because of a messy script + directory, but it’s getting the job done right now.

Thanks for your response!

2 Likes