Installing Arduino Libraries

A library is a collection of related pieces of code compiled and stored together in a single file. That file can be linked to, and referenced in application code, giving access to the functions in the library without having to write them all yourself.

There are multiple ways to install libraries in Arduino from fully automated to manual installations. For a video of how to install an Arduino library using the automated Arduino library manager, check out this video where Jacinta walks you through the complete process.

Unfortunately the Arduino library manager often doesn’t have the most up-to-date library files. In our opinion, the best way to install library files is manually. It’s actually quite easy and just requires a bit of knowledge of how Arduino creates and references folders.

cmdArduino Library

Let’s use the FreakLabs cmdArduino library as an example. The cmdArduino library allows you to create commands to control your hardware directly via the Arduino IDE’s inbuilt serial monitor. This is useful for useful for quickly testing and debugging your application, and devices.

For example, if you’re building a data logger that takes a temperature every hour, you want to test it without waiting every hour to see if it works.

Using cmdArduino, you’d create the following commands: setDateTime, setTimeInterval, getTemp. After you’ve written your application code and downloaded it to the board, you’d type these commands into the serial monitor, setting the time interval to 2 minutes (because you don’t want to wait 1 hour to see if your code works) and then check there’s a reading every 2 minutes and the date, time and temperature is accurate. Once you’re confident it’s correct, you’d set the time interval to 1 hour.

 

Downloading cmdArduino Library

To download the latest version of the FreakLabs cmdArduino library, you first need to go to the Freaklabs Github account.

 

In the right hand corner, there’s a green button called “Code”. If you click on this, you get a dropdown with various menu options. If you click on “Download ZIP”, you can download a zip file of the cmdArduino library.

 

Once you’ve saved this to your hard drive, we can then continue on to the next step in manually installing a library which is where to place the libary.

 

Arduino Folder Structure

The Arduino IDE uses an implicit folder structure where it expects specific files to be in specific folder locations on your hard drive. After installing the Arduino IDE and starting it up, it will create a folder called Arduino on your hard drive. To be certain of the folders location, you can open the Arduino IDE and check the preferences. It will show you the location of the default Arduino directory on your hard drive.

For a quick reference, these are the defaults. You may want to check just to make sure though.

For Windows: C://users/xxxxx/Documents/Arduino

For Mac: ~/Documents/Arduino

For Linux: ~/Arduino

 

 

 

Inside this folder, the Arduino IDE expects three separate folders: hardware, libraries, and sketches.

 

The board files for the specific boards that will be used go into the hardware folder. The sketches you write would go into the sketches folder. If we’re installing libraries, we place them inside the libraries folder. For the cmdArduino zip file, you can copy it into the “…/Arduino/libraries” folder and unzip it there. It will then create the cmdArduino folder and unzip the source code into that directory.

 

Once it’s unipped in the libraries folder, then close the Arduino IDE and restart it. When the Arduino IDE starts up, it will create a database of the available libraries internally which is why the restart is needed any time a library is added. Otherwise, the library won’t be seen. Once it’s restarted, you can go to “Sketch > Include Library” and you should see the cmdArduino library.

 

If you can see it in the menu, that means the library was successfully installed. Any time you need to update the library, you can just overwrite the library folder in the “Arduino/libraries” directory. That’s all there is to manually installing Arduino libraries and gives you ultimate flexibility in installing different libraries and library versions.

Now that we’ve installed libraries, let’s let’s look at the IDE menu and sketch code structure.


Copy link