Installing an Arduino Library
Installing a Library - Mac
This section covers installing a library under the Mac OS X environment. If you’re more of a text learner then check out the Arduino tutorial on installing libraries.
We are going to use the Capacitive Sense library for this example. Navigate to the library’s page and download the zip file.
Find the zip file on your local computer (wherever downloaded files end up). Unzip it, and look at the folder contents.
The contents of the Capacitive Sense zip file. Libraries will usually contain a .cpp file and .h file. Most will also contain an examples folder.
This particular library contains libraries for both the basic Arduino and the more advanced Arduino Due. You can use both if you’d like, but, for this example, we will be copying and installing only the CapacitiveSensor folder.
Now we need to add this folder to the Libraries folder for Arduino. This folder is somewhat hidden in OS X. To get there you can do one of two things. Option one, right-click on the Arduino icon located in your Dock. Go up to ‘Options’, then click ‘Show in Finder’.
Option two, find the Arduino app located in your applications folder within Finder.
Either option should get you to this point. Now, right-click on the Arduino app, and select ‘Show Package Contents’.
Navigate through the following folders, ‘Contents -> Resources -> Java’, until you reach the ‘libraries’ folder. Note: if you don’t have a libraries folder, simply create one here.
Inside the libraries folder is where you want to copy/move the library folder you just downloaded and unzipped. You’ll aslo notice this is where all the default libraries live as well as any other libraries you may have installed in the past.
Note: Arduino does not allow library folders to contain symbols such as hyphens ‘-’. Arduino will throw an error upon starting up. If the library you are installing has a funky folder name then this step is the ideal time to clean it up. Make sure the name of your folder matches the name of the files located within the library folder.
Next, make sure that restart the Arduino IDE if it was open when you installed the library. This is a very important, often overlooked step. If you don’t restart, the library you just installed will not yet be available to the IDE.
To verify the library has been installed correctly, open up the ‘Examples’ folder under the Arduino IDE.
There it is! Let’s open the example provided with our new library.
Examples are the greatest thing about libraries! Good libraries will have well written examples showing how to use the library. These sketches are wonderful resources for example code and learning how to write good code under Arduino.
You now have the Capacitive Sensor library installed! Feel free to start from the example sketch, or begin writing your own code using the functions provided by the library. A library usually has documentation either on its site or written into readme files and example code. In general, to quickly learn how to use a library check out the example code.