Using the micro:bit Internal File System
Sometimes, you may wish to add functionality to your project that is not part of the standard micro:bit library. To import and gain access to the module, you will need to place the library in the micro:bit persistent file system.
The servo library is a prime example of such a module. The servo distribution explicitly instructs on how to import an external module. Just click the servo library link to view the instructions. However, we will use the External tools to work with the micro:bit persistent file system.
First, we will create a new directory called external_files by clicking on the project name at the top of the Project panel.
Follow the instructions here to add the new directory. Name the new directory external_modules.
Now, create a file called servo.py in that directory. Refer to this section for creating files.
Copy the code from the servo library into the file.
Before adding servo.py to the micro:bit persistent file system, let's examine the persistent file system's contents.
Select Tools/External Tools from the main menu by first clicking on the Hamburger icon.
Click on ufs ls. The results are displayed in the Run panel at the bottom of the screen. The file main.py is displayed. This is a default file that is preinstalled with the persistent file system.
Now, let's upload servo.py to the persistent file system.
First, we select servo.py in the Project panel and then choose ufs put in the External Tools menu.
If we now execute ufs ls again, we see that servo.py has been added.
If we now execute a ufs rm followed by a ufs ls, we see that the file was removed.
If you wish to retrieve a file from the persistent file system using ufs get, you must first have a file in the project with the name of the file you want to retrieve, and then select that file name in the Project panel, execute the ufs get external tool.