Arduino libraries, what they are and how to install them
What is a Library?
Software Libraries are very similar. We already studied what a procedure is, in lesson 3 : a procedure is a list of things to do. A library is a big collection of procedures, where all the procedures are related! If you, say, want to control a motor, you may want to find a Motor Control Library: a collection of procedures that have already been written for you that you can use without having to do the dirty work of learning the nuances of motors.
For example, this is the Serial Library, which allows the Arduino to send data back to the computer:
One of the best features of the Arduino project is the ability to add on pre-crafted libraries that add hardware support. There's tons of them, and you can pick and choose which to install. They're only loaded in when the sketch you're working on needs them, so for the most part you can download and stash them for future use.
Sketches will often depend on libraries, you can see what they are by looking at the top of the sketch.
Sketches will often depend on libraries, you can see what they are by looking at the top of the sketch.
Whats in a Library!
A library is a folder with some files in it, the files will end in .cpp (C++ code file) and .h (C++ header file).
There may also be some .o files. The .o files are C++ compiled Objects. If you end up working on the library and modifying it, be sure to delete the .o files as that will force the Arduino IDE to recompile the modified .cpp's into fresh .o's
Two optional files you may see are keywords.txt (this is a hints file to tell the Arduino IDE how to colorize your sketch and examplesfolder, which may have some handy test-sketches. These will show up under the Files/ Examples/ Library dropdown
There may also be some .o files. The .o files are C++ compiled Objects. If you end up working on the library and modifying it, be sure to delete the .o files as that will force the Arduino IDE to recompile the modified .cpp's into fresh .o's
Two optional files you may see are keywords.txt (this is a hints file to tell the Arduino IDE how to colorize your sketch and examplesfolder, which may have some handy test-sketches. These will show up under the Files/ Examples/ Library dropdown
The structure of the library folder is very important! The .c and .h files must be in the 'lowest level' of folders. For example, you cant have Arduino/libraries/WaveHC/WaveHC/file.c or Arduino/libraries/MyLibraries/WaveHC/file.c - it must beArduino/libraries/WaveHC/file.c
How to install librariesIn Arduino v16 and earlier, libraries were stored in the ArduinoInstallDirectory/hardware/libraries folder, which also contained all the built-in libraries (like Wire and Serial).
In v17 and up, the user libraries are now stored in the ArduinoSketchDirectory/libraries folder. You may need to make the librariessub-folder the first time. However, the good thing about this is you wont have to move & reinstall your libraries every time you upgrade the software.
For example, here is how it looks when NewSoftSerial is installed in Windows (of course your username will be different)
After you're done, restart the Arduino IDE
In v17 and up, the user libraries are now stored in the ArduinoSketchDirectory/libraries folder. You may need to make the librariessub-folder the first time. However, the good thing about this is you wont have to move & reinstall your libraries every time you upgrade the software.
For example, here is how it looks when NewSoftSerial is installed in Windows (of course your username will be different)
After you're done, restart the Arduino IDE