As some will be aware, I was initially struggling with getting some good data out of a Temp/Humidity sensor I bought for my new Pico W.
If you're not aware, but interested, you can find that thread here: viewtopic.php?f=21&t=12900
The end result of that, with LOTS of very good help from "Roberthh" (Thank you very much for that Roberthh!) is that I am now getting useful data from that sensor.
Now on to the next challenge!
In addition to the above, and getting MQTT working (see here for that thread: viewtopic.php?f=21&t=12904),
I also need to know how to make my new Pico W code "live" as it were, so that it survives a power down, and automatically starts the code on boot up.
Can Anyone advise me, and guide me on how to do this?
Pico W Micro Python autorun of code even after reboot
Re: Pico W Micro Python autorun of code even after reboot
Okay, so without any assistance, and a bit of googling and watching youtube, I've now become aware of the necessity for boot.py and main.py. This isn't even described in the instruction manual! However, some nice chap on youtube enlightened me to these file naming requirements to get my code to autoboot. *two thumbs up*
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Pico W Micro Python autorun of code even after reboot
Normally you only need main.py.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Pico W Micro Python autorun of code even after reboot
Thanks Peter, I recognise this. I'm sure having a boot.py could be useful perhaps, like maybe engaging the wi-fi since this is something I'd probably always want to do anyway, and then run the main.py on the understanding that the wi-fi is already up and connected? Is this proposed reasonable practice?
Re: Pico W Micro Python autorun of code even after reboot
I've been using boot.py exclusively for like 6 years. I never thought there was any best practice on this, am I mistaken?
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Pico W Micro Python autorun of code even after reboot
boot.py runs before the board is fully configured. The filesystem is set up, but USB is not yet configured. The recommendation is to use main.py to launch your application.
Using boot.py to connect to WiFi should be OK but the official advice is to keep boot.py code minimal.
Using boot.py to connect to WiFi should be OK but the official advice is to keep boot.py code minimal.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Pico W Micro Python autorun of code even after reboot
Ah right. Well it's certainly minimal right now. I've just got it flashing the onboard LED as an indication that it's now definitely powered up!pythoncoder wrote: ↑Tue Aug 16, 2022 5:06 pmboot.py runs before the board is fully configured. The filesystem is set up, but USB is not yet configured. The recommendation is to use main.py to launch your application.
Using boot.py to connect to WiFi should be OK but the official advice is to keep boot.py code minimal.
![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
Re: Pico W Micro Python autorun of code even after reboot
That's right. Any code than runs in boot.py will be unable to print to stdout on boards that use USB to access the console/REPL.pythoncoder wrote: ↑Tue Aug 16, 2022 5:06 pmboot.py runs before the board is fully configured. The filesystem is set up, but USB is not yet configured. The recommendation is to use main.py to launch your application.
The purpose of boot.py is only to configure the peripherals that might be needed to run main.py, such as:
- Filesystems (e.g. mounting block devices, so that you can actually find main.py and other libraries)
- USB (so that main.py can print, etc)
- Network (so that webrepl is ready by the time main.py runs)