#203 SPIFFS vs LITTLEFS for ESP32✅ & ESP8266✅ (not Arduino UNO❌)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
and welcome back now today we have on the workbench an esp32 uh this particular flavor of esp32 is a development board and uh yeah it's got four megabytes of memory on it four megabytes imagine that that's a huge amount isn't it compared to say an arduino uno with just 32k which is why we cannot use spiffs or little fs with an arduino uno or in fact any flavor of arduino frankly you do need quite a bit of memory to do it so an esp8266 with 512 k of of flash memory just about is okay but i'm going to concentrate more on the esp32 because cost wise there's very little in it these days i mean you can get one of these for about five dollars four megabytes dual core processor and it's just it is so fast you would not believe i've done a couple of videos where we've looked at the speed of one of these compared to well a nuno and even an esp8266 and it just it just romps past them i want to give a shout out to my sponsor jlcpcb manufacturers of custom pcbs made simple one of their new features is their smt assembly process and their web page contains a lot of information about what their capabilities are and some various very common facts if you prepare your pcb using easy eda you'll find that when you place components you have the option of using their lcsc assembled catalog as you can see here i've just chosen the ic that i'm going to be using in a future project and it's come up as part of the lcsc assembled list that means they can pick and place it for you on that board if you can try and use their basic list rather than the extended list which means they'll have to change the components in the pick and place machine designing a board could not be easier using easy eda and the fact it links into the jlc pcb website is going to make ordering an assembled smt pcb an absolute breeze why don't you try them out today so esp32 is sorry what's that oh oh this thing at the back yes now this isn't a laptop disk that i've taken out of a laptop that i no longer use and as you can see it says um 250 gigabytes which is a lot of memory right not four meg that we've got on that thing down there 250 gigabytes but whilst the technology for laptop disk has improved immeasurably over the last few years in here is pretty much what we get down here we have loads and loads and loads of flash chips inside here now these have been optimized for speed and longevity and there's a bit of you know intelligence and therefore something called wear leveling so if you keep writing to the same bit of memory there's a finite amount of times you can do that so this thing sorts it all out for you but basically what is on here we have a a sort of a mini micro version of it in here and what we can say is um right arduino ide or whatever is you're using platform yo it works on as well and i use the eclipse system and that works just great we can say look there's four megabytes of memory here i'm only going to use maybe one meg of it for my program and you'd have to write a lot of code to compile down into one meg that would be a big program so the remaining three meg of memory just sits there normally unused i think how wasteful what else could i use it for well the answer is we can say to the to the system to this we can say look we'll have one meg of memory for my programs and then we'll have three mega memory for files just as you would put them on here all right so you'd have a file called you know my text dot file and wi-fi secret stop file and they got to be obviously small enough to fit within the remaining three megabytes on this chip but you can get an awful lot of text up there error messages html pages css javascript you know you can get an awful lot up there in three meg sorry you're still not sure what spiffs is spiffs stands for spi flash file system so spi you've probably heard of or you might even have used rights on all the arduino stuff spi serial peripheral internet yeah i know that's why we call it spi right basically it's just a means of connecting your arduino chip to something else a peripheral using the serial bus and it's three wires three wires plus one extra wire to tell which peripheral it is we're talking to at this precise moment and your flash memory uses exactly that for the spiff's system now the bad news is as you saw from the video title spiffs is dead expressives have said look okay not quite dead but it's deprecated basically they're not going to be improving it anymore they might make some fixes they discover some bugs but basically spiffs only allowed a flat file structure basically no directories no folders right so you'd put text file up there and if you put um slash backup slash text file you think oh i'll put that into another folder no it doesn't it just puts the whole file out there called backup slash text file it's just just another name with some slashes in it it was not a folder system it looked like it might be but it's not there is no folder system there little fs which is the replacement for spiffs does allow you a proper directory structure and you can make directories and put files into directories pretty much as you can with say windows and mac i suspect is is pretty close to that sort of way of doing things as well little fs has been developed one because it's faster to access those files b it's much more resilient so if you're in the middle of writing a file for example and the power goes you pull the plug or the battery dials or whatever you do not corrupt your whole file store and three unfortunately it does require a bigger overhead a minimum of 4k to write those files which on the little esp8266s is probably not a great idea you can get very very small files on there so for the esp8266s with a limited amount of ram like you know 512 or something you probably want to stick with spiffs and there's there's no major advantages removing little fs unless you want the reliability and you've got enough memory you can of course upgrade the esp8266 flash memory to four megabytes if you're handy enough with a soldering iron but that's beyond the scope of this video as they're fond of saying right okay let's let's first of all then look at what you have to do to get the tools in place for that so you can upload stuff onto the esp32 and how easy is it to do it right for i'm going to show you a sketch but it's not the sketch we're looking at first it's the tools behind it now because we're not using spiffs we're using little fs which is the successor to spiffs if you put that included as you can see the line is actually red at the moment because when i compiled it as you might expect it goes i've i've never heard of this what do you mean so we're going to have to find where this library is and as per usual go to tools manage libraries and get a big long list after a few seconds of having a think and type in here type in little f s and hit enter and after a few seconds it says okay i've got these ones here but we want little fs so let's scroll down to that and there it is this is the little fs esp32 the b1 for esp8266 as well i'm going to install that right press install it says it's updating various bits and pieces and it now says version one is installed hooray right now i should be about to compile this with just that single include and it should know all about it let's have a look so we'll click compile and what does it say down here now in this area oh look it seems to have found it now so let that be a warning case sensitive and in fact this doesn't even conform to what expressive say in their documentation marvellous so there we are the sketch uses uh 217k even though we've done absolutely nothing so obviously the stuff is in little fs i guess right here's a simple sketch that's going to demonstrate little fs and spiffs is almost identical right you can almost replace the word little fs for spiffs in all the code that you have at the moment and it would work pretty much the same but i'm concentrating on little fs because that's the way forward and i'm using an esp32 anyway with four megabytes memory so it's the obvious choice now first of all let's have a look at your tools memory if you click on tools in your ide and you do not see these two entries here esp32 sketch data upload or esp32 esp8266 sketch data upload then you haven't installed the tools how to do that very very easy luckily somebody's done all the grump work for us and has put all the file stuff together and it's it's so easy let's go through steps one two and three and see what we need to do first right the first thing you need to do is head off to this website i'll put the address that's up here into the video description down below and into the github if there is one for this video so this developer laurel has created this esp32fs plugin now you can read up about it here there's quite a few notes and all that but basically what you need to do you can either go over to over here releases so let's go to that one right so this is the current release the time you watch this of course this might have changed but um there we are he only released this look 12 days ago it's october 2020 now in case you're watching this so i suspect you know there may be some changes going forward so the there are three files here you need to download okay now they might change in the future so do read that readme on his github first basically you need the esp32fs zip you also need the mk fs zip and then for windows at least you need this x86 64 w64 but if you're on linux or macintosh then you need these other two instead so you download those now when you extract all these if you look inside look you see here there's a folder that's called mk little fs and if you go into that you'll find the actual executable so as you can see here here's my arduino sketches folder now that could be literally anywhere i've just got it on a on a drive so wherever you place normally your sketches you know the the folders for all your sketches go there and create one called tools if you haven't already got it just create a brand new tools directory or folder and then within that copy the esp32fs directory that says tool and within the tool you've got these three that we've extracted now you'll know you've done it right because you then have to shut down your arduino ide just count to three when it's down load it back up and you'll see those for those tools appear as if by magic like i showed you before okay now the esp8266 one is done similarly you can go to his github exactly the same copy it down into folder and it will appear here so to recap within your arduino sketches folder wherever that may be you need to create if it's not already then it probably won't be if you've never done this before a folder called tools great within that we open it up you'll see that we have the esp32 fs folder now if we open that up you'll see there's one called tool and within that you have the three well i would call them executables that one's a java a piece of code but that's where the three align right okay enough of that i think you can work it out how to get it working from that if it doesn't appear in your arduino ide after you've restarted the arduino ide you need to go back and have a look at that right i'm going to assume then that in your tools drop down now you have that esp32 sketch data upload now what that means is you can upload the any files within a folder called data that's in your sketch so yeah i know there's all these folders i know but you have to do this step by step fairly logically now this um esp32 spiffs demo one let me bring that up for you in in internet explorer not in internet explorer in windows explorer just to show you what i mean right so within my arduino sketches folder for esp32 spiff's demo one obviously the sketchup is going to be called the same as that if we open up that folder we can see in there there's my sketch the one that you can just see in the background there and here i've created another folder called data and it's the data folder contents that get uploaded to your esp32 or esp8266 now if we open that one up you can see i've created two files one called spiff's demo and wi-fi secrets there we are if you can read this from the arduino sketch then you are successfully reading a spiffs file um well let's see if we can upload it to the esp32 and write a very small sketch to read it and then we're sort of halfway there aren't we really so you might be thinking at this point great in my tools i can see the esp32 sketch data upload tool so i can go yeah hold your horses hold your horses what we haven't done yet is told the arduino and indeed the esp32 how we want to partition that memory so you need to plug in your esp32 select it from the drop-down list and as you can see here i've got esp32 dev module right let's whiz through these right your upload speed to an esp32 is always going to be 921600 we want to get it up quick right if you select one of these other speeds it will just take longer frankly right the frequency of an esp32 well we might as well run it at full speed why not why are we running an esp32 otherwise flash frequency is 80 megahertz if you have any problems with your flash frequency you might have to bring it down to 40 but i have flash mode we're leaving it at quad input output because that's the quickest way of getting stuff in and out of flash memory right flash size now i've said four meg although when we try and upload something the arduino is not stupid it says i'm going to go and check this and it goes and has a read of your chip and see what your chip reports back how much memory core debug level well i've said info i'm not sure it matters too much when it crashes basically how much information do you want splatted out psram we're not using that at the moment so we disable that that's that's a topic for another video and the port is of course the port that you want this to well that you've connected it up to yeah right back to partition then now i've said minimal basically 700 kb of spiffs um basically because i want things to happen quickly in a demo if i'd said you know three mega spiffs whenever you upload something out of that little data folder from your arduino sketch it says oh you've only got 2k of data here great but oh i've now got right the remainder of that 3 megabytes of spiffs because that's the way it works apparently it just splats over the top of it now as you can see there's lots of other options here with no ota and then various amounts of spiffs and app right it just splits the four meg equally so two and two one meg and three make two mega two mega and so on no oh so what's that ota over the air yes i'll have to do another video about that basically with an esp32 you can you can reserve a portion of this flash memory to say look my sketch is only 700 kb and i want to upload that sketch over the air not connected as we've got it on here via usb cable i want to do it via wi-fi so i can connect my esp32 say oi i've got another program for you upload this well where's the esp32 going to put it well it puts it into this particular flash partition that it knows about and then it will upload it into proper program memory but that's a subject for a different video not this one all right that's that's enough about this i think so i've selected that but nothing's actually happened yet has it i mean i've told it that's what i want to happen so you saw that data folder within my sketch folder that had those two files yes spiff's demo text one or whatever it said and the wi-fi secrets one maybe we should upload that now tools esp32 sketch data upload yes please now that's asking me now what type of spiffs system are you using there little fs which is now the approved successor spiffs or fat fs which i haven't even investigated or do you want to raise all the flash there is the whole thing do you want to erase everything uh no i i think we'll stick with little fs because that's what i've used is it happens okay so we click that and say okay and then we'll see what happens right and off it goes you can see all the messages down here and it's connecting to my esp32 on comm 6 and oh look it's changed the baud rate to 92 1 600 the upload and it says i've done it there's no error messages anyway somewhere it will tell me the files that it's found to upload here we are see these two here spiff's demo text and wi-fi secrets dot text it goes oh that's what i found in that data folder i've uploaded them hurrah so now we just upload this sketch in the normal course of events so upload let's go and there's always a bit of a delay isn't in the arduino ide these days i think it it's gone to sleep or something hurrah we're connecting and we're uploading magic great that took quite a long time right so let's reset the esp32 but we want to bring in the serial monitor port don't we now a word of warning if you bring up the serial monitor and then you try to upload that data right into the spiffs or little fs partition it will fail you must close the monitor first right let's open it up here it is and um not a lot's happened because i think we've we've missed the boat it's run and finished and well the loop does nothing okay let me reset the esp32 you get a lot of crud at the front of it that tells you a little bit there we go little mount fs successful that's good oh look listing the directory yes it's found them reading the file spiff's demo text file opens successfully reading from file if you can read this from the arduino sketch you are successfully reading a spiffs file well it's a lie it's a little fs file but we've done it hurrah what we've done we've proven that it works right having got the little fs thing working we've uploaded it we've partitioned it we've loaded the data we've loaded the sketch the two are hanging together it's time to look at the code really gosh this video is going to go on forever right this is the sketch now what the sketch is going to do is mount the little fs system first right it's got to read the partition and go oh yes i understand what that is that's fine we're up and running then it's going to look at the directory structure and print out any files it can find and thirdly it's going to find that demo sketch text and just read it and output it's three things right very simple let's whiz through this in a couple of minutes right so we include the little fs library otherwise nothing's going to work now this particular value is used when we mount the file system if we say right we've got a little fs system here go and mount it it goes i can't find one because it wasn't a little f little fs it was a spiffs or something else you put there it's gonna say i can't find one i'll create one for you and splat everything that's there no that probably isn't what you want if you've already got one there and you've got files in it and for some reason it can't mount it you do not want it to delete everything so i've set that as you can see there to false all right so when we load it here with the begin statement i say no do not splash it and format a brand new one if you can't find one just say i couldn't do it and return okay now the first time of course you ever do this you will have to let it format it you'll have to set that for true the very first time you do it on your esp32 okay now we're we're listing the directory that's a little routine down the bottom i'll share that in a second and what we're saying here now is here's here's my spiff's demo text right um go and read it so we say file file open the path the path being this bit here for reading not writing obviously you can write and append and do all sorts of things here if we couldn't get it error message otherwise it says yes i've done it and of course all this is because it's a demo program right you wouldn't put all this kind of stuff in there for a real program and then we just say whilst there's stuff to print go and read it and print it out which is exactly what we did and then finally it doesn't always say to do this but it does say you have to end the little fs mounting procedure when you want to upload something over the air but we'll come on to that in a future video at the moment i've just put it in there because after all this is the end of the sketch at this point because in the loop we do nothing except to yield right this is the list and i've stolen this basically from espresso example how to list the directory i wasn't going to go and rewrite that all again it's just a little thing and that's it so as you can see the actual sketch is pretty easy and this will be up on the github for you to peruse in your own time it's worth having a look at though and then you can perhaps try to extend it by appending some stuff to that file yeah and then rereading it perhaps and making sure that it's all worked okay well as a sort of a a basic intro into little fs and spiffs the two are sort of interchangeable but you can only use one file system per device uh per sketch right so if if you mix them up as i did initially then you will get an error when it tries to mount that file system i think we're done here for now i think i think we've had enough there's probably umpteen links down below and in the github and everywhere for you to read up about this but it is simple once you've got your head around how to put the tools in and where that library is as well okay so i would strongly recommend if you're an arduino person go out and buy an esp32 they're only five dollars or they're about five six dollars yeah oh if you use my link that's an affiliate link and if enough people buy stuff i actually get a small commission that helps me buy more stuff to show you so that's a win-win isn't it so yeah go and buy one plug it all in and get this bit working i mean it's not difficult and then you'll realize that instead of using an sd card in your sketches you can actually use the spiffs or little fs file system instead and it's just so much easier especially when we get around to uploading stuff over the air which will be the subject of a future video okay in the meantime looking forward to comments down below and i'll see you in the next video i hope you're finding these videos useful and interesting there are plenty more videos to choose and a couple are shown below and if you'd like to subscribe to this channel just click on my picture below and enjoy the rest of the videos thanks for watching
Info
Channel: Ralph S Bacon
Views: 38,232
Rating: undefined out of 5
Keywords: Arduino, Beginners, electronics, C++, microcontrollers, programming, gadgets, ardiuno, spifs, litlefs
Id: 4r6YZlLfKfw
Channel Id: undefined
Length: 25min 28sec (1528 seconds)
Published: Fri Oct 30 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.