Re: Code Execution: You can run Python scripts and programs directly from within the IDE.

139 views
Skip to first unread message
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Aivar Annamaa

unread,
Oct 25, 2023, 3:54:53 AM10/25/23
to thonny
> Once the program is entered you can click the Run icon and select where you want the program to run – locally or on the Pico

This sentence is misleading. Thonny allows you to select where you want to save your editor content, but with MicroPython interpreter you're always running it on the MicroPython device. When you press F5, Thonny takes the editor content and submits it to MicroPython's REPL for execution. It doesn't matter, whether the editor is saved to local file, a file on the MP device or is not saved at all.

If you have single-file program, then during the development it's OK to keep saving to the local copy of the program and running it from there. Once you're confident the code works and you want to disconnect your device from Thonny, you would export it to the device (e.g. with "File => Save copy as" or via Upload command in Thonny's file browser). This approach doesn't work as well if you have your code broken into several modules -- if the main code imports something, this something must be present on the device (you can still postpone saving the main code to the device).

Best regards,
Aivar

On Tuesday, October 24, 2023 at 8:41:07 PM UTC+3 thonny wrote:
I think you are confusing where the file is saved. I've never entered a program and tried to run it without saving. When I save it, it asks if I want to save it on the PICO or host. Regardless, when you RUN it, the contents of the editor are copied to the PICO to run. The only way I know that you can change 'where' it runs is to change the interpreter in Options->Interpreter.

On Tuesday, October 24, 2023 at 1:16:59 PM UTC-4 recursos pt wrote:
Thank  you for your answer.
From the book:
Programming the Raspberry Pi Pico_W in MicroPython
Harry Fairhead, Mike James 2022

"Once the program is entered you can click the Run icon and select
where you want the program to run – locally or on the Pico:
...
If you select the Pico, you will be asked to provide a name for the program.
Use “helloworld” and it will be downloaded to the Pico and run.
MicroPython creates a small filing system on the Pico and you can save and
open files stored there using Thonny."

Dwonloading and running on the Pico (from Flash) that i understand, is the normal way with any uController.
But running locally (on the PC), I can't understand how it interfaces with the hardware.

On Tuesday, October 24, 2023 at 5:36:47 PM UTC+1 thonny wrote:
I can't find a reference, but Thonny does not run execute the script. It is passed to the Python interpreter in Options->Interpreter. In the case on micropython, this is the interpreter on the board Thonny is connected to. Not sure that answers your question.

On Tuesday, October 24, 2023 at 10:58:17 AM UTC-4 thonny wrote:
"Code Execution: You can run Python scripts and programs directly from within the IDE."
But when interfacing with hardware, like GPIOs, where is the code running, if not downloaded to the target?
Reply all
Reply to author
Forward
Message has been deleted
0 new messages