Part of script wont run when named main.py or boot.py #9852
-
Hi micropython team, I am using a RaspiPico W RP 2040 with micropython and this is the script Im trying to autorun when Pico is powered. I plan on powering the pico with an external power brick.
More details: |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 5 replies
-
In general the best approach is to save your program under a different name, say import test When it's fully working, then edit import time
time.sleep(3)
import test I find the delay useful in the case where something goes wrong and the program locks up the device. It gives you time to reset the device and issue |
Beta Was this translation helpful? Give feedback.
-
Do you mean "output to the display" or "REPL output" ? In my opinion, you can't trust thonny (or any other colorful IDE) when you want to know what really happens on the board. Use pyshell or mpremote to verify that your script has been copied to the device (and there are no older boot.py/main.py versions left). |
Beta Was this translation helpful? Give feedback.
-
If I can offer another general comment. This isn't intended as a criticism of Thonny or any other IDE, but an IDE is another layer of software which has the potential for problems. I think is the point being made by @karfas. When confronted with a puzzling problem I recommend using the simplest, most reliable, tools available to access the device under test. In my opinion these are official mpremote and unofficial rshell; in extremis I use a terminal emulator - my choice is miniterm.py. |
Beta Was this translation helpful? Give feedback.
-
Thank you for the suggestions everyone, I will keep in mind to use the REPL more often. |
Beta Was this translation helpful? Give feedback.
-
As an update to the problem, I have it named boot.py and now it will boot right into the script but the script now encounters memory allocation errors more often. |
Beta Was this translation helpful? Give feedback.
-
No. But to be sure to have the best state of the heap, call gc.collect() at the start of the script. |
Beta Was this translation helpful? Give feedback.
In general the best approach is to save your program under a different name, say
test.py
. This enables you to test it by issuingWhen it's fully working, then edit
main.py
as follows:I find the delay useful in the case where something goes wrong and the program locks up the device. It gives you time to reset the device and issue
ctrl-c
to regain control.