While developing programs for the Raspberry Pi Pico (W) with MicroPython I use Thonny to write programs and transfer them to the Pico. And while using Thonny I discovered some handy features which are not obvious.
Transfer data files
It is obvious that you can type MicroPython programs into Thonny's editor and save them on your Pico. And as a backup you can also save them on your computer. But what if you need to transfer data files like pictures or audio files to your Pico.
The above picture shows that I am trying to open a .wav file in Thonny.
To no avail. Thonny will give an error saying that it can not read this file as an UTF-8 text. Well not only that, it can not read that file at all.
The solution is easy. First create a new directory (folder) on your Pico. I gave it the name Sounds2. Double-click on that folder to open it.
Right-click on the file and the submenu shows the option: Upload to Sounds2. And that is just what we want.
Transfer multiple files.
I wanted to upload multiple files to my Pico. So I could select them one by one and choose the above described upload method. But that would be a tedious job.
Just like you are used in Windows you can select a bunch of files and upload them all.
Select the first file with the left mousebutton.
Scroll down till you see the last file and shift-click on that file with the left mousebutton. The files background will turn gray so you can see which files are selected.
Next click on the right mousebutton and select upload to /Sounds2 and all selected files will get transferred to the chosen folder/directory.
How much space is left
The Pico's flash memory is limited to 2Mb. In those 2Mb the MicroPython language is stored. But also all your programs are stored. So before uploading multiple files to your pico's memory it is wise to know how much memory is available.
On the right side of your Pico's directory there is a hamburger menu (3 small horizontal lines). Clicking that menu a pop-up menu appears and in there is the option: Storage space.
Clickin that option shows how much storage is free in the Pico's memory. In this example there is just 64k flash momory left.
From the 2MB flash memory 848k is used for MicroPython. In this example 784K is used for MicroPython programs and data files. And there is just 64K free space left.
How large are individual files
In my example it is time to free up some space, That is not easy as I need the sound (.wav) files for a project. So I am going to delete some other files.
Select a file in Pico's directory and click on it with the righ mousebutton. The option properties in the pop-up menu shows how much memory that particular file occupies.
Now you know how much memory this program takes you can copy it to your computer with the Download option in that menu or just delete it.
What is this all about.
Well as you can see I am uploading .wav files to my Pico. These are audio files. So the project I am working on is to have the Pico play audio. And it works. What's more: the quality is outstanding !! Much better as the speech synthesises that was produced by the ESP32 featured in several stories on this weblog.
To produce audio on the Pico you only need a few (6) resistors and a capacitor that function as a low pass filter. This will be explained in an upcoming story. So keep following this weblog.
Till next time,
have fun
Luc Volders
Friday, July 14, 2023
A few small Thonny tips
For an index to all my stories click this text
Labels:
Micropython,
Raspberry Pico