I can't see files that exist on the Pico with explorer

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
Popsimath
Posts: 4
Joined: Sun Feb 07, 2021 2:44 pm

I can't see files that exist on the Pico with explorer

Post by Popsimath » Sun Feb 07, 2021 4:07 pm

If I drag and drop files there I can see them but after it powers off and back on they are apparently gone.

Using Thonny, with the Pico interpreter, I have installed Python ON the Pico several times but it apparently doesn't stay on there becasue it asks me everytime if I power down.

So I write some code like an external LED blinker, save it to the Pico, execute it. It works fine. unplug the pico, plug it back in and I can't see it with windows explorer.

BUT it seems to be there. If I tell Thonny to open a file on the pico l it can see all my old files, except the ones I drag and drop.

Someone said don't push the boot select button when I boot.
I tried that but then the Pico doesn't show up in Explorer. BUT still seems to be accessible from Thonny.

So are these files saved on the Pico or not? and if so, Why can't I see them with Explorer?
How can install Python on the Pico permanently?

User avatar
jimmo
Posts: 2244
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: I can't see files that exist on the Pico with explorer

Post by jimmo » Mon Feb 08, 2021 6:31 am

Popsimath wrote:
Sun Feb 07, 2021 4:07 pm
So are these files saved on the Pico or not? and if so, Why can't I see them with Explorer?
How can install Python on the Pico permanently?
The Pico works a bit differently to other MicroPython boards such as pyboard (or pretty much all CircuitPython boards) which present a USB storage device.

On the Pico, USB storage is only used for the bootloader (this is referred to as "UF2"). You use this _only_ to install firmware onto the board (such as the MicroPython firmware).

Once MicroPython is installed, it will stay installed permanently. When MicroPython is running, the device is only a USB serial port, and tools like Thonny talk to the serial port to list and transfer files.

Popsimath
Posts: 4
Joined: Sun Feb 07, 2021 2:44 pm

Re: I can't see files that exist on the Pico with explorer

Post by Popsimath » Mon Feb 08, 2021 11:41 am

ok I held the bootloader button down when I plugged it it and heard the connection sound.
Opened Thonny and it aske if I want to install on computer or Pico and I chose Pico.
It installed and said it was done.
I closed Thonny and opened it back up.
The shell was running and said: MicroPython v1.14 on 2021-02-02; Raspberry Pi Pico with RP2040
So Thonny is interacting with the Pico

I Click open and it asks whether to open files from the computer or the Pico
I choose Pico and it lists files that I had written and saved, apparently on the Pico?
That seems to contradict what you said that USB storage is only used for the bootloader.
And how would my scripts run for imbedded projects if they weren't on board?
I must have a mental block on this but I sometimes do.

And if the Pico does store scripts, how can I move libraries on to it?
Would I have to copy and paste them into Thonny and then save to the Pico?
That seems a bit archaic for a modern device but I can't see how to manage (move) files in Thonny.
There is a move/rename function but it only renames, it doesn't really move.
Thank you for your response!!

User avatar
aivarannamaa
Posts: 109
Joined: Fri Sep 22, 2017 3:19 pm
Location: Estonia
Contact:

Re: I can't see files that exist on the Pico with explorer

Post by aivarannamaa » Mon Feb 08, 2021 12:55 pm

Popsimath wrote:
Mon Feb 08, 2021 11:41 am
I choose Pico and it lists files that I had written and saved, apparently on the Pico?
That seems to contradict what you said that USB storage is only used for the bootloader.
And how would my scripts run for imbedded projects if they weren't on board?

Your scripts are on the device, they simply are not exposed via a USB volume. Instead, you need to access them somehow via MicroPython. Thonny does it for you. For example, when you ask Thonny to save a script onto the device, behind the curtains something like this happens on your device's MicroPython REPL (simplified):

Code: Select all

>>> __temp_file = open("main.py", "w")
>>> __temp_file.write(b"import machine\n")
>>> __temp_file.write(b"\n")
>>> __temp_file.write(b"print('blah, blah')\n")
....
>>> __temp_file.close()
In order to list the files on the device, Thonny does os.listdir() etc.

Popsimath wrote:
Mon Feb 08, 2021 11:41 am
And if the Pico does store scripts, how can I move libraries on to it?
Would I have to copy and paste them into Thonny and then save to the Pico?
For transferring files you don't want to edit in Thonny, you should open Thonny's file browser (View => Files). In order to upload a library:

* in the upper pane navigate to its location on your local disk (double click on a directory to go into it)
* navigate to "lib" directory in the lower pane (use the small sandwich button for "Create new directory" command)
* right-click on the source file/directory and select "Upload to /lib".

I'll try to make this process it more discoverable in Thonny 4.0.
Aivar Annamaa
https://thonny.org

Popsimath
Posts: 4
Joined: Sun Feb 07, 2021 2:44 pm

Re: I can't see files that exist on the Pico with explorer

Post by Popsimath » Mon Feb 08, 2021 2:57 pm

Very helpful thank you aivarannamaa.
I was able to see the files both on my computer and on the Pico with Thonny's file browser.
IO was able to transfer a library file from my computer onto the Pico.
However, I created a Directory on the Pico but then could not figure out how to get the file into that directory.
Drag and Drop didn't work.
I could not select the new directory with the Right click option Download to
I could not change the upper window to the Pico
I deleted the file and tried downloading it again into the new directory but that was not an option, it only downloads to the pico.
So I guess that's ok. It would be nice to used directories to organize my files since there seems to be plenty of space.
Unless there's a way I'm missing? Probably. I hope.

BTW I'm trying to set up a LCD1602 output from the onboard temp sensor and a humidity sensor.

User avatar
aivarannamaa
Posts: 109
Joined: Fri Sep 22, 2017 3:19 pm
Location: Estonia
Contact:

Re: I can't see files that exist on the Pico with explorer

Post by aivarannamaa » Mon Feb 08, 2021 3:09 pm

Popsimath wrote:
Mon Feb 08, 2021 2:57 pm
However, I created a Directory on the Pico but then could not figure out how to get the file into that directory.
Do you mean moving files around on Pico? Thonny does not have an UI for this, but you should be able to use os.rename for this.

If you meant uploading files into specific directory on Pico, then you need to first double click this directory on Pico's pane and then do the upload:
Screenshot from 2021-02-08 17-07-00.png
Screenshot from 2021-02-08 17-07-00.png (31.36 KiB) Viewed 216 times
Aivar Annamaa
https://thonny.org

Popsimath
Posts: 4
Joined: Sun Feb 07, 2021 2:44 pm

Re: I can't see files that exist on the Pico with explorer

Post by Popsimath » Mon Feb 08, 2021 9:40 pm

specific directory on Pico. That worked! thanks for your help.

Post Reply