How to set up an Arduino Library :: Video #1 :: Arduino Library Series

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hey how's it going I hope you're doing really well we're going to talk about Arduino libraries today we're going to talk about why you might want to use them and we're going to talk just going to go ahead and stall a couple we're going to talk about some of the things that can mess up if you don't do a couple things when you're installing a library so I'm doing this because a friend of mine Roman asked me to do it you know he just emailed me and hey hey said hey I'm having some trouble with some libraries can you show me what the deal is so you know and as I looked into it you know there are a couple things that really can kind of hold you up so we're going to talk about those things too alright so here I am in here do we know ite and you know maybe I was on the internet and I was looking around and it said hey you you should use this library to do you know XYZ like maybe you want to run a matrix or something and there's a library out there running all matrices you're like okay hey I need that library so you know the first thing you might want to do is check do I already have you know I'm getting ahead of myself well what is a library and Arduino library is just a group of functions that are packaged together that are similar okay so there's a bunch of different functions they all do the same kind of thing like they you know run a four by four matrix and then you pack them together and that's called a library that's really it that's it and then you know a library makes it easy to share these functions with one another so the Arduino IDE already comes with pre-installed libraries so if you go up to tools and you go to I'm sorry if you go to sketch you go to import library here right here this big list right here these are libraries that are already installed on your dwee no IDE so if you were to click let's go ahead and click the servo alright so if I click servo see how it adds that code right there include servo dot H that line of code right there saying hey you want to look through the servo library before you go ahead and execute the rest of this code okay that'll make sense here in a second but that's when you go to again when you go to sketch import library all that's going to do is add a line of code to your sketch now if you know the name of the lie library you can type it in yourself right there you don't need you know that's all that really does now notice down here I have contributed and I have a couple libraries down here so this first one that is a AF motor that's Adafruit motor so if you ever heard of Adafruit that's a company that makes hardware stuff like that open-source hardware and so I bought one of the things and I used that one of the libraries they made with it in frequency time or two I think that's also an Adafruit one I'm not sure so I've used those are the two libraries that I have on this installation so a contributed library is just a library that anybody else is written that doesn't come prepackaged in your Arduino IDE there's tons of them out there and it's a really good idea before you start a project to start looking for libraries that might help you with a project so let's say you wanted to interface with a certain piece of hardware maybe you have some temperature sensor well and you're looking at it you're like man this temperature sensor the status sheets like you know 40 pages long and I'm not really sure I get this and it's going to take me you know four years to figure this out well you know get online and do a search for a library in that component name like Arduino library slash temperature sensor sensor and you might find like forty people have written libraries for a you know the specific temperature sensor and essentially they've really done the work for you and then all you have to do is kind of familiarize yourself with the library and get going from there so it really libraries really help you kind of jumpstart your project okay so highly recommend looking for libraries and using them so let's go ahead now okay so we've kind of looked at it you know where the libraries are here but now I want to show you what's in a library file for ttle folder alright and that might seem a little higher level like you know what do I really care well this is knowing what I'm about to show you is going to help you down the road when you start installing libraries okay so what I'm going to do is I am going to go ahead and I'm going to navigate to where I have my arduino installation all right so here's arduino you have this same folder on your computer and now see these are all the sketches that i've written on this computer okay and in here there is a folder called libraries and that is where all your library folders are so here look at this here's AF motor so remember when I was on the Arduino IDE you saw AF motor in frequency time or two so I'm going to go ahead and click here and look we've got a couple files in here so we've got frequency time or two dot CPP and frequency time or 2 h ok this file that dot CPP file and this file the dot H file are the two required files you're going to need to see in any Arduino library let me say that one more time there's two mandatory must-have files and one is going to end in dot H and one is going to end in dot CPP alright I think CPP stands for c++ and dot H stands for header okay so the header file is like a list of all the names of the function and the dot CPP file is the source coder that's like the actual line-by-line programming of the functions okay it doesn't I'm not going to get nitty-gritty on what these are it doesn't really matter you just need to make sure that there's a dot CPP and a dot H file now what you could also find in here is a key word file and that's a text document and all that does is that like you know when you type in a function in Arduino and it turns a color like it turns you know digital read I think is orange well this file defines different colors so like that you could set a keyword for the different functions and then an examples folder that gives you that will allow you to have access to examples when you're in the Arduino IDE so here's one it says test and there's test PDE ok so let me show you where this is real quick if we come to Arduino IDE when we go to sketch I'm sorry we go to file examples see here frequency timer - do you see that here's an example of this library ok so I hit test should open up a little fold it opens up a thing here and now here is a test here's an example of using this library ok so most libraries have examples that come in them alright so here we are on this library folder this is what I want to talk about here notice that there are several files in a library so what that means when somebody wants to deliver a library to you it has to be or it's most likely going to be in a zip file ok because all the zip file does I'm sure you're familiar with it is it packaged packages together a bunch of different file types in a cozy little blanket okay so by necessity every library that you download is going to be in a zip file now you're you know I I'm not trying to you know pretend that you're ignorant I'm sure you notice it file is but I just want to talk through it real quick so we're both on the same page so when you get a zip file you're going to have to unzip it and then it's going to have a folder okay and so when you download a library generally when you unzip it you're going to see a folder and it's going to be the name of that library so when I downloaded to AF motor it was you know AF motor dot zip and I unzipped it and then it makes this folder AF motor and then here's all these files in there okay so let's go ahead and just do an example alright of downloading and setting up a folder so or a library rather so go to the arduino webpage go to reference references my favorite page on the Arduino website and let's click on the libraries tab now I am going to go to this link here it's called tutorial on writing your own libraries it's a really good tutorial now we're not going to talk about writing our own library but what I want to do here is give you an example of a library that's made okay so if you scroll down all the way down to the bottom there is a library called Morse zip so I'm going to go ahead and click on this and it's going to ask me where do I want to save it notice that there's that dot one okay I've already downloaded this before so I'm going to go ahead and save it under the name Morse in oops I'm going to go ahead and hit save here it'll ask me yes I do want to replace that so it's downloaded and so now what I'm going to do is I'm going to go back to all my files I'm going to find out what you know where I had downloaded that so it's let's see here downloads programs to install theirs here's my file now this is what's important so it doesn't matter where you save the zip file doesn't matter a bit what matters is where when you open when you unzip that file where the files go so what I'm going to do first is I'm going to show you how to do it from the Arduino IDE so here we have there's more stat zip we've downloaded so I'm going to go to my arduino ide and i'm going to go and we get rid of this here i don't want that i'm going to go up to tools i'm sorry sketch import library and see you says add library so I'm gonna go add library and now I'm going to navigate to where I just downloaded that alright so let's see downloads programs to install I'm going to look for more so I'm going to kind of navigate there's more stat zip the zip file and now I'm going to say choose and look down here it says libraries Edie library added to your libraries ok so now I'm going to go up here to sketch import library and I want to look down here a look at that contributed there's Morse so it just added it so when I click this all it does is adds that little include Morse dot H okay and that's the header file and that basically allows the program to access that library now when you compile this code so let's go ahead and take a look at the Arduino you know the Arduino file folder at Moore's and take a look at what that is so documents o programmer Arduino ok let's come down to the library folder ok everybody's going to have a libraries folder in their Arduino installation and there it is hey there's more so I'm gonna go ahead and click on this and look at this there's those two files that you had to have more stat CPP or more stats CPP and more stage and they've got some examples all right there's SOS and then there's a keywords ok so if I so just basically what happened when I use that the Arduino way to do this they're the built in thing I go to tools an import library and I hit add library what it's going to do you're going to point it to the zip file that you download and then behind the scenes Arduino is going to unzip that file and it's going to put it in the libraries folder in your Arduino directory okay so you need to know where your Arduino directory is on your computer should be pretty easy you know just find out where the Arduino folder is all your sketches are going to be in there like mine remember so I'll just open this up one more time just in case so you know I go I happen to have it in my documents for some particular reason and see here's my Arduino folder here's all the sketches that I ever write they get saved in folders and then in here you are going to find a libraries folder and then this is where all your libraries the individual folders for your libraries end up being so now let's talk about some issues we can run into I'm going to talk about it right here first this is what this is what issue you will probably you can run into at times the name of the dot CP pile file the dot H file in the folder all need to be the same so see how this is Morse the name of that folders Morse and the name of CP is Morse and the name of dot H is Morse that those all have to be the same let's go on to AF motor notice this AF motor AF motor and then the folders name is AF motor frequency timer to look they're all the same frequency timer to frequency timer to dot CPP frequency timer to H it is absolutely necessary that all of those names are the exact same so let's give it a real-life example of where this is becomes an issue okay let's go back to the Arduino website I'm going to go to the home page here actually you know what I can search right here and this is one that Roman had mentioned so I'm just going to go to search for timer one and here's so let's click on this timer one and here is a library talks about a library timer 3 all right here it is timer 1 Google code download so I'm going to go ahead and click on this link and Here I am takes me to a code repository that Google has ok and look there's two different zip files all right so here I'm already at a point where I'm like wait a sec well which one do I get you know I've kind of was weird like which one do I want to take well if you read the name one is called V 9 and 1 is called R 11 so I'm guessing v 9 stands for version 9 and R eleven stands for revision 11 all right so there's really no similar naming convention there that makes you wonder like well what's the deal and I could be completely wrong about what v 9 and hour 11 stand for but or you could look at like the release date so this one was February of 2012 this was October so the most recent one is in October so no another thing you could look at is choose the download count this one man this one's been downloaded a lot this one not so much so maybe this one is the more popular one well I'm going to go ahead and go with timer one so I'm just going to click on it and it's going to ask me to it's going to take me here and now I want to download that alright I'll just click this download so it's going to ask me where do I want to download it you'll notice I've already downloaded it I am going to actually I'm going to name it this right here so timer 1 - R 1 1 and I'll save that ok now what I will do is so I've saved it alright so let's go ahead and go into our dueño and see what happens when i try to import that library so i'm going to go to tools oh man sketch import library add library now i'm going to navigate to where i did that so i will go to where i downloaded that library here's downloads and i'm trying to remember what the name of that library was that i just installed it was timer 1 that's right ok timer 1 alright so I'm going to choose that library oh hey what's this I get a little caution down here says the library timer 1rr cannot be used library names must contain only basic letters and numbers ascii only in no spaces it cannot start with a number so there is an a problem with the naming convention of this library so if I come up let's just verify if I come to sketch import library notice that it didn't get added here so what we need to do so this is it this is actually a pretty common problem so this is what we need to do let's go find out where we let's go find out where we downloaded that file downloads programs to install timer1 alright so what I'm going to do is I am going to open this file with my archive utility and windows would be like WinZip probably ok I'm going to click on this and it's going to expand it out right there ok so notice that look I've got examples dot CP and timer dot H ok so here's all the files right here here's the examples and here's that collective folder that those are all in so what I'm going to do now is I am gonna I'm going to copy that alright and I'm going to put it in my Arduino directory so I'm going to come to where my Arduino installation is so I go to documents programmer Arduino I'm going to come down to that libraries folder okay here's the libraries folder and now I'm going to paste that item so here's timer 1a it's all in here but wait a second do you notice what the issue is look these do not match that folder name and those names the dot CP and the CPP and the dot H file they have are not the same name so let me change the name of this folder to timer dot 1 or just timer 1 now they all match don't they that's easy enough I mean that was nothing crazy I just made sure that all those files were the same name I could name this you know Arduino 1-2-3 or I could name it or 42 it doesn't really matter as long as it's the same name okay so that is taken care of so now let's go ahead here's our Arduino IDE and I just want to show you something real quick if I go if I go to sketch import library notice that it's not under contributed it did not get added here the reason that is is we have to restart Arduino so I'm going to ahead and quit Arduino I don't need to save that and I will go ahead and open up your dwee no IDE again and now let's go to sketch import library and there it is look at that timer one now it got added okay so here's timer one and we're again all it does is say it includes timer one well let's go ahead and take a look at the example examples timer one read receiver so here's an example of the read receiver and you know if we wanted to use this it could be installed so that's basically how you install a library okay so there's two ways to do it the first way is you just go to sketch import library add library all right and then you navigate to the zip file that you downloaded for that library and then arduino behind-the-scenes is going to automatically pull that or it's going to unzip that file and it's going to put it in your libraries folder so there's option one option two is you download that zip file you locate it on your own you know you find out where you installed it you unzip it you know and then you copy that folder and then you you yourself move that folder over to wherever you have your arduino installation at again and the arduino installation is just going to say arduino and you know you've come down to the libraries folder which will you will have and then you just paste it in there yourself and then you just got to make sure that those names are the same and that's really how to set up a library it's that easy okay now using the library is something a little different we can talk about that later but that's kind of getting a library set up so that's that now one quick thing I will do will show you real quick here if you go to if you're wondering where your Arduino installation is set up maybe you just you don't happen to know if you go to file and I'm sorry if you go to our dwee no preferences this is going to show you where you need to go so mine is users my name documents programmer Arduino okay so this is going to tell you the file path to where that our dueño folder is that we just talked about and if you hit browse it'll take you right there okay so you can find it easily if you don't happen to know off the top of your head okay well that is that I hope that was helpful and I'm going to be doing a lot more of these in this coming year so if you have a question about Arduino shoot me an email go to the website it's open source hardware group comm go to the website you should definitely sign up for the course the Arduino course if you haven't yet it's a free course it'll get you spun up on Arduino sign up for that there you can get my contact information send me an email if you have a specific question and I'll do my best to make a tutorial hopefully it will be helpful alright have a great day and take it easy bye
Info
Channel: Programming Electronics Academy
Views: 133,894
Rating: 4.8813791 out of 5
Keywords: Arduino (Computing Platform), Library (Building Function), arduino library, how to, arduino class, arduino tutorial, arduino tutorial for beginners, arduino library tutorial, arduino library install, arduino programming, arduino programming for beginners, arduino basics, arduino basics 101, arduino basic programming, arduino basic programming tutorial, arduino basic coding, arduino basic to advanced, programming arduino for beginners, programming arduino
Id: fsMg6F6yYlo
Channel Id: undefined
Length: 21min 15sec (1275 seconds)
Published: Thu Jan 02 2014
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.