Introduction
A library is a group of functions and declarations, that are used in Arduino IDE scripts. The library consists of an interface expressed in a .h file (named the header) and an implementation expressed in a .cpp file. The header file contains all the declarations and the .cpp file contains definitions of functions declared in the header file.
Libraries make it easy to connect to a sensor, display, module, etc. E.g. if you want to control your evive TFT display, you can use the evive Library. It has predefined functions for writing text, drawing a line and many more. It eliminates the need to make complicated functions on own; the user can simply use the corresponding library.
Installing a library
There are three ways in which you can install a library:
- Using the Library Manager
- Importing a .zip Library
- Manual Installation (Not covered in this tutorial. To know more visit here)
-
Using the Library Manager
Follow the steps below to install a new library in Arduino IDE using the Library Manager:
- Open Arduino IDE and click to the Sketch tab. Then, click on Include Library > Manage Libraries.
- The library manager will open and you will find a list of libraries that are already installed or ready for installation. Scroll through the list to find the library you want you to install; then select the version of the library you want to install. Sometimes only one version of the library is available.
- Finally, click on install and wait for the IDE to install the new library. Downloading may take time depending on your connection speed. Once it has finished, the Installed tag should appear next to the installed library. You can now close the library manager.
-
Importing a .zip Library (evive Library Installation)
Libraries are often distributed as a ZIP file or folder. For this example, we will import evive library. You can download it from here. Generally, the name of the folder is the name of the library. There will be a .cpp file, a .h file, often a keywords.txt file, examples folder, and other files required by the library inside the folder. DO NOT unzip the downloaded library, leave it as it is.
Follow the steps below to import a .zip Library:
- Open Arduino IDE and click to the Sketch tab. Then, click on Include Library and select Add .ZIP Library; you can find it at the top of the drop-down menu.
- You will be prompted to select the library you would like to add. Navigate to the evive.zip file’s location and open it.
- Return to the Sketch and select Import Library menu. You should now see the library at the bottom of the drop-down menu. It is ready for use in the sketch. The zip file will have been expanded in the libraries folder in your Arduino sketches directory.
How to include a Library in your Sketch
Follow the steps below to include a library in a sketch:
- Navigate to Sketch > Include Library and select the library you want to include.
In this example, we are going to include evive.h.
#include <evive.h>
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}