The Raspberry Pi Pico File Management System - (Ep. 0.1)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] welcome to life with david i'm david and today i've got a raspberry pi picot this little four dollar microcontroller is the recent brainchild of the raspberry pi foundation it's kind of a cross between an arduino and a raspberry pi there are lots of getting started with your raspberry pi pico videos out there so i'm not gonna do another one you can check out the pico video from dronebot workshop for a good introduction on how to interface a pico to many devices however while most people see a really nifty controller that runs c c plus plus a micro python i see a potential data storage device for my 6502 computer i don't even know if it's possible so why don't you join me as we look into data handling capabilities of the raspberry pi pico the raspberry pi pico is a small microcontroller that has 256 kilobytes of static ram and 2 megabytes of onboard flash memory that's tiny by today's standards but in the world of 8-bit computers it's pretty big back in the day i was excited to have 160 kilobytes of disk storage on my 300 five and a quarter inch floppy disk drive and the pico only cost four dollars today we're going to look at the little fs version 2 file system implemented in micro python for the pico this is a little fail-safe file system that works well on systems with limited ram and raw since microcontrollers can experience unexpected power interruptions little fs has a robust scheme to guard against data loss this same scheme is used for dynamic wear leveling of the flash memory you may know that a block of flash memory needs to be erased before fresh data can be written onto it this is a pretty traumatic event for the memory chip and a block of memory can only stand about a hundred thousand cycles before it breaks down little fs spreads the data around the chip to make sure that the entire chip wears evenly this means that for our use the flash memory will last years if you're interested you can read the little fs design document for more information i'll put a link in the description below luckily we don't have to get into the gory details of little fs micro python has taken care of that for us so let's get into the pico and see how we can handle data storage and retrieval first let's load micro python onto the pico i'm using a windows pc but i think this procedure will also work with an apple download the micro python uf2 file from the raspberry pi website into your computer i'll put a link in the description below then hold down the boot cell button on the pico and plug it into your pc the pico will mount as a mass storage device called rpi-rp2 then drag the micropython uf2 file you just downloaded into the rpi-rp2 volume the pico will reboot and will now be running micro python you can communicate with the pico through the usb cable using many different applications i'm using thawney and will put a link in the description after you start thani click on the button at the bottom right corner of the window you should see a drop down from the list choose micro python raspberry pi pico you should now be connected to your pico in order to access the operating system in micro python you need to import the os library type import os and then enter now we can type os dot and then the tab key to see the choices we have for using the operating system let's go through the list and describe each function micro python has a multi-level hierarchical file system similar to other computers when the pico is initially booted there is only the root directory designed by a forward slash you can add directories under the root directory to aid in organizing your data the basic format for the operating system functions is os dot the name of the function followed by a set of parentheses what's inside the parenthesis depends on the function sometimes there's nothing and sometimes it's a directory or file name any names must be surrounded by single quotation marks let's add a subdirectory called new directory using the make directory function starting from the parent directory type os dot mkdir and include the name of the new subdirectory in the parenthesis we can move into the new directory using the change directory function use os.chdir along with the name of the directory you can also use the complete file path by using forward slashes between directories and like linux and ms-dos you can move up one level by using double dot instead of the directory name how do you know what directory you're in you can use the get working directory function os dot g e t cwd followed by empty parenthesis the directory path is listed with the different directories separated by forward slashes this is similar to the pwd command in linux let's go back to the root directory we'll use the change directory function with two dots to move up one level what's inside the directory use the list directory function to find out type os.listtdir followed by empty parenthesis a list of the directories and files under the parent directory is printed out here we can see our newly added directory you can remove a directory by using the remove directory function type os dot rmdir followed by the name of the directory to remove when we use list directory again we see that the directory new directory has been deleted the list directory function can also be used to create a list of file and directory names [Music] [Music] to get more information about the structure of the directory you can use the iterator list directory function this returns an iterator which will yield tuples that return the name of the entries the entry type which would be four zero zero zero hex for directories and eight zero zero zero hex for files the inode of the file which is usually zero for our purposes and the size of the file this has the complexity of creating an iterator variable but it could be useful in designing a disk operating system for my 6502 [Music] we can get even more information about the individual entry by using the status function use os.stat and the name of the file or directory this will create a tuple that includes the type of entry a bunch of other data which is usually zero for our application the size of the file and the times of entry creation modification the clock has to be set though for the times to mean anything here's the status function demonstrated by using the file data1.txt [Music] for information about the file system use the status virtual file system function use oas dot st a t v f s with a forward slash this will generate a tuple that contains the file system block size the fragment size the total size of the file system in blocks the number of free blocks and other information that doesn't apply to this application the total drive capacity can be determined by multiplying the block size times the total number of blocks in this case about 1.44 megabytes the remaining space can be determined using the number of free blocks remaining note that the maximum file name length is 255 characters we can get information about the pico and micro python system we are using with the udam function use os dot u n a m e with empty parenthesis this reports the system name node name micro python release version and date and the machine name there are a couple more functions that will help us manage the file system the remove function will remove a file from the file system use os dot remove along with the name of the file to delete when we list the directory contents we see the file has been deleted remember there's no recycle bin so when the file is gone it's gone for good you can rename either a file or directory by using the rename function use os dot r-e-n-a-m-e and include the old and new names respectively here we are renaming the directory dir to new name finally there are three functions that don't apply to what we're doing the vfs lfs2 function allows advanced users low level access to the gory details of little fs version 2. this allows them to do a format of flash memory as well as to change operating parameters of the file system notice i said them because we're not going to mess with this function the pico doesn't have any removable flash storage and the parameters have already been optimized by the developers since there are no removable flash storage the mount and unmount functions also don't apply now that we've covered the file system operation let's try to create save and read a file from micropython in this case these functions are the same as in python here we'll open a new file using f equals open and the name of the new file followed by a w to indicate we want to write to the file [Music] we can enter the information into the file by using f dot write and the data we want to add [Music] finally to keep things tidy we'll close f by using f dot close now let's go back and list the contents of the directory there's our new file when we're ready to read the file we can open it using f equals open with the file name and an r to indicate we want to read the file the file contents is actually read using f dot read [Music] finally close the file by f dot close i think this demonstrates that i have enough flexibility to use the pico as a little disk drive for my 6502 computer thanks for joining me today we examine the file system for the raspberry pi pico and i've determined that it could be used as a circuit disk system for my 6502 homebrew computer i'm not sure yet how i'll handle the data and command information it might be a mix of a bi-directional parallel port and i2c communications i'll figure that out in the next few months so stay tuned if you like this video or you think someone else might please give a thumbs up if not give it a thumbs down the more likes this video has the more youtube will recommend it to others also please leave a comment or suggestion for things to do i hope to do more of these videos so please subscribe and click on the bell for notifications of new videos let's get together next time for another day in life with david see you soon you
Info
Channel: Life with David
Views: 9,342
Rating: undefined out of 5
Keywords: Raspberry Pi Pico, File system, Operating system, file management, Thonny, MicroPython, Read and Write, OS Library
Id: G06tPDjZ3zM
Channel Id: undefined
Length: 16min 20sec (980 seconds)
Published: Sun Mar 14 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.