All About the Raspberry Pi Pico File System

Raspberry Pi Pico Over Dell Laptop Keyboard Feature Image

Have you tried playing around with the Raspberry Pi Pico file system? Have you tried storing anything else besides Python script files? If you’re new to the concept of flash memory, then you probably didn’t know that you can store almost anything on a Raspberry Pi Pico – that is, as long as it’s within 2 megabytes.

How the Raspberry Pi Pico File System Works

The Raspberry Pi Pico file system is where you store your files and firmware. It’s as big as the RP2040 chip’s onboard flash memory, which is right around 2 MB.

Raspberry Pi Rp2040 Chip Closeup
image source: Wikimedia Commons

Looks small? Well yeah, it is small. But it isn’t too small for most work done on a Pico. For perspective, a simple “Blink” program is just around 168 bytes. You can store roughly 12 thousand of these on a Pico!

What makes the flash memory really special is that you can store files there and they won’t disappear when you turn the power off. It’s like a tiny USB flash drive that doesn’t show up on your file explorer’s drive list.

Kodak 16gb Usb Flash Drive By Terenz Jomar Dela Cruz

And like a USB flash drive, you can navigate through its files list to create, delete, view, and copy files as you like.

This way, you can store as many scripts and programs as you want within the Pico. You can add functionalities that don’t disappear. Or you could create code that could push the Pico’s abilities past its theoretical limits.

Contents Inside a Raspberry Pi Pico

There are four general things typically inside the Pico’s flash memory:

  • The MicroPython / CircuitPython firmware and their standard libraries
  • 3rd party libraries
  • Custom modules
  • Your Python script/s
  • Save files

When you start off with a clean firmware install, your Pico will contain nothing else but the firmware within the flash memory. You won’t really see these files, but they’re there and taking up space. The other four come around as you work on a project.

Thonny Files Within A Raspberry Pi Pico Project

You can make new files, delete what you don’t need, and modify them all for as much as you need.

It’s also good idea to store data within custom save files, instead of solely relying on Python variables. This is so you can keep them there even after you’ve turned the power off.

1. Thonny “Magic Commands”

On Thonny, there are these things we call “Magic Commands.” These are functions that use % before a command, like %run.

Here’s a list of useful navigation commands and what they do:

  • %run "PATH" – Runs the file in the path.
  • %cd "PATH" – Changes the current working directory.
  • %debug "PATH" – Debugs the file in the path.
  • %delete "PATH" – Deletes the file in the path.

In case you haven’t noticed it yet, there isn’t much you can do with Thonny magic commands. You can’t copy, cut, nor rename files. If you want to do more, then you’ll have to use something else.

2. Manually Making and Deleting Files

While you certainly can’t see your Pico files within the Windows File Explorer, you can still see them through Thonny.

Here’s how to configure Thonny so you can have a go at the Pico files by yourself:

  1. Go to View -> Files.
Thonny Red Arows On View And Files
  1. A sidebar on the left side should show up. This is where your files are.
Thonny Red Box And Arrow On File View Tray
  1. You can right-click on any file, folder, or an empty space to do other things with them.
Thonny Right Click On File View Tray

3. The OS Module

Now this one’s for the heavyweight Pico users out there. The OS module lets you do things that normally requires an Operating System to work. This includes navigating through the Raspberry Pi Pico file system.

To use this, you’ll need to enter import os on the Thonny Shell to import the OS module. You’ll only ever need to do this once whenever you open Thonny..

import os text on thonny shell
Thonny Shell Import Os To Navigate Through Raspberry Pi Pico File System Using Os Commands

After that, here’s a list of commands you can use to navigate the Raspberry Pi Pico file system:

  • os.getcwd() – Displays the current working directory’s name. Stands for get current working directory.
  • os.chdir("PATH") – Move the current working directory. Use os.chdir("..") to move up one level. Stands for check directory.
  • os.listdir("PATH") – Lists down all the files and folders directly within the current working directory. Stands for list directory.
  • os.mkdir("PATH") – Creates a new folder. Stands for make directory.
  • os.remove("PATH") – Deletes the selected path, file, or folder.
  • os.rename("OLD PATH", "NEW PATH") – Renames the current selected file or folder. Accepts whitespace.

What’s Next?

Now you know how the Raspberry Pi Pico file system works, you can do a combination of methods to work around and do things. You can make some sort of a minimal OS during normal operation using the OS module, for example.

Using custom save files, you can even give your Pico some sort of a backup memory. It can take a while to store something in an SD card module, after all. If the power suddenly goes out while saving, you can still retrieve the original data stored within the Pico’s flash memory to make up for the broken save.

You could also make a script or program interact with the Pico during development using Thonny Magic Commands. There’s just so many things you can now do with the Raspberry Pi Pico Filesystem!

Frequently Asked Questions

Can the Raspberry Pi Pico store C header files?

The Raspberry Pi Pico can store C header files. However, it might not be able to use it if it doesn’t have access to a compiler.

How do you import scripts contained within folders in MicroPython?

Importing scripts hidden under layers of folders in MicroPython works just as they would in normal Python. You use dot notation to move from your main python script’s working directory down to the script you’re trying to pick. For example, you can import a script hidden in ./test/apps/ by typing import.test.apps.script.

Is it impossible to store an OS inside a Raspberry Pi Pico?

Depending on how you would stretch the definition of an operating system, you might be able to store some sort of a minimal OS in there. You can also store an OS inside a memory card connected to it. But you’ll need to hack a lot of other hardware together for the Pico to use even a proper OS at all.

Subscribe to our newsletter!

Get the best of IoT Tech Trends delivered right to your inbox!

Terenz Jomar Dela Cruz

Terenz is a hobbyist roboticist trying to make the most awesome robot the world has ever seen! He would have done that already if he wasn't so busy burning through LEDs.