Download all arduino libraries in one archive. Where to find the required library

Installing and connecting a library to arduino is a fairly common operation; sooner or later any developer will inevitably encounter it. External plug-in code in all programming languages ​​is used to save time. Arduino is no exception: many sensors, modules, screens and motors require quite complex circuits interactions that are difficult to implement in your code. Much easier and faster to download the required library, quickly connect it manually or using Arduino IDE, and then use it in all your sketches. In this article you will find short instructions on connecting and using libraries.

A library in Arduino is a program code in external files, which can be installed and connected to your sketch. The library contains various methods and data structures that are needed to simplify work with sensors, indicators, modules and other components. Using libraries greatly simplifies working on projects because you can focus on the main logic of the program without wasting time on a lot of little things. Today great amount libraries are posted on the Internet, where they can be easily downloaded, and completely free. can be found on our website.

From point of view file system library is a directory containing specific folders. During compilation and assembly Arduino project The IDE automatically includes in your code those classes, data structures, and methods from libraries that are included and used in the sketch. Thus, the only thing we need to do is to put the appropriate instructions in our code, after making sure that the required library is installed.

How to find out the list of connected libraries to Arduino IDE

Each installed library contains one or more examples to work with. They are used to display the capabilities of the device connected to the Arduino. Therefore, the most in a fast way get a list of all installed Arduino libraries - use the list of examples in the Arduino IDE. To do this, select File from the main menu, and then open the Examples submenu.

Another way is to use the Sketch menu and the submenu – Include Library. There you can also see a list of libraries:

Connecting the header h file with the #include operator

To start using the library, you need to include the h header file with the include directive at the beginning of the program. For example, including the LiquidCrystal.h library will look like this: #include

You can see complete example using the library itself.

Required files in the library

Each library must contain at least 2 files - a header file with the extension .h and a file with source code with extension .cpp. The header file contains the class description, constants and variables. The second file contains method codes. In addition to the two main files, it may contain text documents keywords.txt and the examples folder with codes for examples of using the library. The h and cpp files are not necessarily located in the root

Editing files is not possible in the Arduino IDE; all changes can be made in any text editor, or the C++ development environment. This is due to the fact that in the Arduino IDE we do not work with cpp files, the code editor is not designed for “pure” C, it only works with the Arduino language.

Where to find the required library

The required library can be downloaded via the Internet. Most libraries are available on Github. After downloading the library, it is important to add it to correct folder, so that the compiler can find it and load the sketch. The folder in which all the codes are saved is created on the computer after installing the Arduino IDE. For operating system Linux folder has the name “Scetchbook” and is located in /home/; on Windows, the “Arduino” folder can be found in the “My Documents” section.

All libraries that are installed additionally are located in the “Libraries” folder. For earlier versions of Arduino, you need to create the folder yourself, but starting from version 1.0.2, it is added automatically when installing the Arduino IDE.

How to install the library. Step-by-step instruction

Once the library is downloaded to your PC, you need to start installing it. There are two ways to install the library - using the Arduino IDE and manually.

Connection using Arduino IDE

The library is downloaded as a zip archive. To enable it using this method, the archive does not need to be unpacked. To install it, you need to go to the Sketch menu – Connect library – Add.Zip library.

When the window opens, you need to select the “downloads” folder in the “This PC” section. If, after downloading the library, it was saved to another location, you need to specify it.

Then you need to select the downloaded file and click “open”.

The library will be installed and you can use it. In order to start using the examples File - examples, you need to restart the Arduino development environment.

Installing the library manually from a zip file

Before starting the installation, you need to exit the Arduino IDE. The downloaded zip file with the library needs to be unpacked. As a result, we will get a folder in which library files with the extension .cpp and .h and directories will be located. The resulting folder will need to be placed in libraries.

In Windows OS, the libraries folder can be found under the My Documents – Arduino – libraries route. On Linux this will be the libraries folder with sketches.

At the end, you need to restart the Arduino IDE, the downloaded library will be available for inclusion via Sketch - Connect Library.

Errors when connecting the Arduino library

Below is a list possible errors when installing libraries and ways to deal with them:

  • ‘xxxx’ does not name a type – a similar error appears if the library has not yet been installed, the folder or library is named incorrectly, specified wrong address folder location or the Arduino IDE has not been restarted.
  • Wrong location folders – if this error is displayed, you need to check whether the library is located in a folder that can be searched by the environment.
  • Invalid library name – the error appears if the name after #include does not match the library name.
  • Incomplete library – may appear if not all necessary files and folders have been downloaded.
  • Library dependencies - since this type of library only works with additional ones, you need to initially include them.

The library already contains most of the code that you will not need to write, the library makes it easier to work with a specific module or one of their types and you just need to include it in your sketch.

For example, if you want to output text to LCD display without connecting the library, then you need to transfer several bytes of commands and data to it, which will take several lines of code, and most importantly, you need to know the type of microcontroller under which the LCD display operates, the purpose of the commands by which it is controlled, know the architecture of its memory, addresses and purpose of registers, for which you will need to find and re-read its datasheet.

While when writing code using a library (for example LiquidCrystal_I2C.h), you can display text by calling just one library function:

Lcd.print(“my text”);

You can connect any library with the following command:

"#include<файл.h>"

<файл.h>– this is the very library that we are connecting.

You can also see an example of connecting the library in the article.

Before you start using the methods and functions of the library, you need to:

  • download (download to your computer),
  • install (place in the desired folder),
  • to plug (insert the text “#include<файл.h>” into the sketch).

Each library must contain 2 files with extensions .h And .cpp.

The first type of files contains:

  • class description,
  • constants,
  • variables.

The second type contains method codes.

Additionally, you need to understand that files .h And .cpp may not be in the root of the downloaded archive. Also included with the main files are “keywords.txt” and a folder with examples.

How to install the library?

After you have downloaded (uploaded) the library to your computer, you need to install it. You can install the library manually or do it using the Arduino IDE:

Installing the library using Arduino IDE

We will do this through the menu. Go to the menu:

Sketch – Connect library – Add .ZIP library

In the window that appears, click on the “This PC” icon and select the “Downloads” folder. If when downloading ZIP archive and from the site, you specified the path to save the file, then instead of the “Downloads” folder, indicate the path to the file.

Select the library ZIP file you downloaded. The file name may not match the library name. Then click on the “ Open » ( Open ).

At this point, the installation of the library is complete, you can start connecting it to the sketch.

Important! After installing the Arduino IDE on the computer, it is created separate folder to store all libraries. For Linux OS "Scetchbook", located in /home/. For Windows OS, the "Arduino" folder is located in /My Documents/.

Installing the library manually

Unpack the ZIP archive you downloaded and place the folder (the folder name usually matches the name of the library) from of this archive to folder:

This computer Documentation Arduino libraries

If the Arduino IDE was running (open) during copying, then you need to close all windows of this program, then launch (open) the Arduino IDE and you can start connecting the library to the sketch.

The fact is that the program is constantly evolving and the number of its versions is constantly growing. If you want to install new version Arduino IDE, then the libraries located in the folder ( This computer → Documents → Arduino → libraries) will be available in both the old and new (installed) Arduino versions IDE, and the libraries are located in the folder libraries Arduino IDE programs old version(which was installed earlier) will be available only in it (until you copy them to the new one).

Where can I find the library I need?

For convenience, there is a whole section on our website called -. Most libraries can be found on the Internet in the public domain.

Also, a number of standard kits can be found on the official Arduino website: arduino.cc.

What libraries are already installed?

As we already discussed - the IDE itself already comes with some .

There are two ways to view installed libraries.

Method 1

To see which set is already installed, go to the tab:

Method 2

The second way is to use the "Sketch" menu and the "Connect Library" submenu. This way you can also see the list of libraries.

Go to Sketch and select Include library:

Sketch → Include library

Possible mistakes

Sometimes, when installing libraries or while using them, some errors may occur. Below we will look at the main ones.

‘xxxx’ does not name a type

The error appears when the library is not yet installed.

The error also occurs if the folder or library has the wrong name.

The folder location may be incorrectly specified or the Arduino IDE may not have been restarted!

Incorrect folder location

Check if all libraries are in to the right address. Folder addresses for different operating systems we cited above.

Invalid library name

The error appears when the name after the #include tag does not match the library name.

Incomplete library

Everyone is missing necessary files and folders.

Library dependencies

It is necessary to connect additional dependent libraries without which correct/correct operation is impossible.

This document describes the creation of a library for Arduino. The explanation will begin with writing a sketch of transmitting Morse code using an LED. Then it will be shown how to convert the sketch into a library. This will allow other users to easily use the created code, update and expand it.

Sketch reproducing Morse code:

Int pin = 13; void setup() ( pinMode(pin, OUTPUT); ) void loop() ( dot(); dot(); dot(); dash(); dash(); dash(); dot(); dot(); dot(); delay(3000); ) void dot() ( digitalWrite(pin, HIGH); delay(250); digitalWrite(pin, LOW); delay(250); ) void dash() ( digitalWrite(pin, HIGH) ); delay(1000); digitalWrite(pin, LOW);

This sketch generates an SOS signal by flashing the LED on pin 13.

The sketch contains a number of pieces of code that will need to be transferred to the library. Firstly, these are the functions dot() And dash(), which control the blinking of the LED. Secondly, it is a variable ledPin, determining which I/O port to use. And finally, the function call pinMode(), which sets the output mode on the I/O port being used .

The process of converting a sketch into a library.

The library contains two files: a header file (with the .h extension) and implementation files (with the .cpp extension). The header file contains the characteristics of the library, i.e. a list of everything contained in it. The header file generated will be called Morse.h. For further work with the header file, you need to look at the contents of the implementation file.

The header file contains a class in which functions are declared and the variables used:

Class Morse ( public: Morse(int pin); void dot(); void dash(); private: int _pin; );

Class in in this case this is a set of functions and variables combined in one place. Functions and variables can be public ( public), which means general access to them everyone who uses the library, or private ( private), which means they can only be accessed within the class. Each class has special function constructor, which is used to create an instance of a class. The constructor has the same name as the class, but does not have a return type.

Also the header file contains several more additional lines. Firstly, this is a directive #include, which gives access to standard types and constant language Arduino programming(the default directive is added to each sketch, but not to the library). The directive looks like this (and is located above the class declaration):

#include "WProgram.h"

In Arduino versions 1.0 and higher you also need to add:

#include Arduino.h

It is also common to enclose the contents of the header file in the following structure:

#ifndef Morse_h #define Morse_h // #include directives and code goes here #endif

This prevents our library from being included again if someone mistakenly includes the library twice with a directive #include.

At the beginning of the library code it is customary to place a comment about its purpose, author, date and license for the library.

The finished header file contains:

/* Morse.h - Library for flashing Morse code.

Created by David A. Mellis, November 2, 2007. Released into the public domain. */ #ifndef Morse_h #define Morse_h #include "WProgram.h" class Morse ( public: Morse(int pin); void dot(); void dash(); private: int _pin; ); #endif

Let's look at the Morse.cpp implementation file. #include There are several directives at the beginning of the code . These directives allow access to standard functions

Arduino and to the characteristics in the head library file:

#include "WProgram.h" #include "Morse.h"

Next in the code is the constructor. It is used to create an instance of the class being created. In this case, the user specifies the number of the I/O port used via a parameter. The port is set to output mode and the number is stored in a private variable for use in other functions:

Morse::Morse(int pin) ( pinMode(pin, OUTPUT); _pin = pin; ) Code:: Morse . means the function belongs to the Morse class _ Lower space at the beginning of the variable name pin Lower space at the beginning of the variable name).

is the accepted notation for private variables. In general, the name can be anything, but according to accepted naming conventions, it is customary to use the prefix “_” for private variables. This also makes it possible to distinguish from a function argument (in this case

Void Morse::dot() ( digitalWrite(_pin, HIGH); delay(250); digitalWrite(_pin, LOW); delay(250); ) void Morse::dash() ( digitalWrite(_pin, HIGH); delay( 1000); digitalWrite(_pin, LOW); It is common to place some explanatory comments at the beginning of the code in the implementation file. Full code

libraries:

/* Morse.cpp - Library for flashing Morse code.

Created by David A. Mellis, November 2, 2007. Released into the public domain. */ #include "WProgram.h" #include "Morse.h" Morse::Morse(int pin) ( pinMode(pin, OUTPUT); _pin = pin; ) void Morse::dot() ( digitalWrite(_pin, HIGH ); delay(250); digitalWrite(_pin, LOW); void Morse::dash() ( digitalWrite(_pin, HIGH); delay(1000); digitalWrite(_pin, LOW); delay(250 ; ) Code Using the library. First, you need to create a folder in a subfolder libraries notepad directories. Secondly, you need to copy the Morse.h and Morse.cpp files to the soz this folder the Morse Library will be located. The library will be compiled together with sketches that use it. If problems arise when compiling the library, you need to check that its files have the extensions .cpp and .h (there should not be any additional extensions .pde and .txt).

The initial sketch, rewritten using the created library, will look like this:

#include Morse morse(13); void setup() ( ) void loop() ( morse.dot(); morse.dot(); morse.dot(); morse.dash(); morse.dash(); morse.dash(); morse.dot (); morse.dot(); morse.dot();

A few differences from the original sketch:

First, directives have been added #include to the beginning of the sketch. This determines the availability of the Morse library and its connection. An unused library can be removed by removing the directive #include.

Second, an instance of the Morse class is created, called morse:

Morse morse(13);

When executing this line (before executing the function setup()) the constructor for the Morse class is called and takes the argument given in example (13).

In this case, the function setup() does not contain anything, because The pinMode() function call occurred inside the library (when the class instance was created).

Third, for calling functions dot() And dash() prefix must be added morse. - name of the instance used. There can be multiple instances of the Morse class, each with its own port number stored in a local variable _pin. A function call on a particular instance determines which variables are used during the call. Given the following two lines:

Morse morse(13); Morse morse2(12);

inside a call morse2.dot(), variable _pin will have a value of 12.

Unfortunately, automatic code highlighting does not work with plug-in libraries. In order for the backlight to work, you need to create a file called keywords.txt. Example:

Morse KEYWORD1 dash KEYWORD2 dot KEYWORD2

Opposite each line, separated by a tab, is a reserved word, and again, separated by a tab, the type of word. The classes correspond to the reserved word KEYWORD1 and are colored Orange color; functions are KEYWORD2 and are colored brown. To recognize words, you need to restart the Arduino development environment.

It is advisable to always accompany the created library with an example of its use. A folder is created for this examples in the directory Code. Then the SOS sketch created earlier is copied to this folder. (The sketch file can be found through the menu Sketch > ShowSketchFolder). After restarting Arduino in the menu File > Sketchbook > Examples there will be a point Library-Morse, containing an example. You should also add comments on how best to use the library.

For easier and productive work With Arduino it is possible to use additional libraries. Arduino libraries are parts of a program to execute specific tasks. Using libraries you can do complex actions just a couple of lines of code because someone else has already written some of the code for you.

In Arduino IDE user-friendly interface for working with Arduino libraries. Directly from the program menu you can download, install and connect many libraries to your sketch. For most Arduino libraries, you can see examples of use. This will help you understand how the library works. The examples can be modified to suit your needs and used to implement your own devices.

Exist standard libraries, which are installed with the Arduino IDE. Some of them are even automatically included in the sketch (for example Serial).

Download Arduino Standard Libraries

You can download the standard libraries on the official Arduino website.

There you will find descriptions and examples of using standard libraries. You can also download all standard libraries in one archive. This archive contains not only standard libraries, but also many additional most popular libraries for Arduino.

Below are detailed descriptions and examples of using the Arduino standard libraries.

  • — Library for data exchange via serial port(UART).
  • — Library for easy and precise control of servos.
  • — Library for working with TWI/I2C communication interfaces. Simplifies the exchange of data with devices, sensors and probes.
  • WiFi— Internet connection with using WiFi shield.
  • TFT— Needed for drawing text, images and pictures on TFT display Arduino.
  • stepper— Library for controlling stepper motors.
  • LiquidCrystal— For working Arduino with liquid crystal screens (LCD)
  • Ethernet— To connect to the Internet using .
  • SD— Library for writing and reading information from SD memory cards.
  • GSM— Library for connecting Arduino to GSM networks. Required for shipping and receiving SMS and calls, as well as to access the Internet using GPRS. Used with .
  • EEPROM— Library for reading and writing to Arduino non-volatile memory.

Arduino libraries are a convenient tool for distributing code. For example, these could be hardware drivers or frequently used functions.

This guide describes in detail how to install libraries on your computer.

There are two main types of Arduino libraries: standard and additional.

Standard Libraries

The Arduino IDE has a set of standard libraries that are used very often. These libraries support all the examples that are included in the Arduino IDE. Standard libraries support functions for working with the most common peripheral equipment, for example: servo motors or LCD screens.

Standard libraries are installed in the "Libraries" folder when installing the Arduino IDE. If you have multiple versions of the IDE installed, each version will have its own set of libraries. It is strongly recommended not to change standard libraries and install additional ones in the same folder.

Additional libraries

There is a huge amount posted on the Internet additional libraries with convenient functionality and drivers for various peripheral equipment. Libraries are mainly posted on Arduino Playground, Github and Google Code. The writing of libraries for Arduino is often done by manufacturers of sensors, transducers, printed circuit boards and so on. For example, Adafruit offers more than 100 libraries that support all models of Arduino boards.

Install additional libraries in the Libraries folder. Thanks to this, they can be used in all versions of the Arduino IDE. After updating the version, you won't have to reinstall them!

Where to install libraries

It is important to install the libraries in the correct folder. Otherwise, the compiler won't be able to find them when you compile and load your code.

The folder where everything is stored Arduino sketches, is created automatically when you install the IDE.

On Linux the folder is called "Scetchbook" and is usually located in /home/<username>

On Windows and Macintosh, the folder is called "Arduino" and is located Documents folder(My Documents).

Please note, this is important! In the "My Documents" folder, another folder called "Arduino" is automatically created!

Additional libraries should be located in the "Libraries" folder, which is located inside the "Scetchbook" or "Arduino". This is where the IDE will look for additionally installed libraries.

From Arduino IDE 1.0.2 and later, the "Libraries" folder is created automatically. For more earlier versions it must be created before installing your first library.

Open the menu and select "File->Preferences" in the Arduino IDE.

>

Find the location of your sketches. This is usually the "Arduino" folder in your "My Documents" folder.

Once you have determined the path, navigate to that folder using File Explorer.


If the Libraries folder does not exist, create a new folder.


Rename it to "Libraries".

Installing libraries on Windows

To install the library on Windows, follow the instructions below.

Close Arduino IDE

Make sure the Arduino IDE is closed, as libraries are scanned only when the IDE is loaded. The new library will not work until you restart the IDE.

Download Zip File from Github.


Copy the unzipped folder


Paste it into your libraries folder.


Give it to her correct name. Arduino IDE does not recognize folders with a dash in the name. So you will have to rename the folder. You can use under dashes.


Restart the Arduino IDE and check if the library appears in the File->Examples menu item.

To check, download one of the examples.


Before uploading the example to the board, check the sketch.


Installing libraries on Mac OSX

For correct installation additional libraries on Mac OSX, follow the instructions below

Close Arduino IDE.

Download the library archive from Github.


Find the downloaded archive in the downloads folder on your Mac.


Unzip and copy the library to the libraries folder that was created when you installed the Arduino IDE.


Give the library a valid name. As is the case with Windows, folders with dashes are not readable.


Restart Arduino IDE. The library should appear in the File->Examples menu.

Download one of the examples.


Please check that the sketch is correct before uploading it to your Arduino.

Installing libraries on Linux

To install custom libraries on Linux, follow the instructions below.

Again, close the Ardino IDE.

Download the archive with the library we need.


We save the archive to HDD our PC.


Find the downloaded archive in the downloads folder.


Unzip the library and copy it to the Sketchbook/Libraries folder.


Give the folder the correct name. No dash!


Restart the Arduino IDE and check if the library appears in the File->Examples menu folder.

Let's download one of the examples.


We check whether the example file compiles without errors.


Common mistakes when installing libraries for Arduino

"xxxx" does not name a type


This is the most common mistake when working with external libraries. The reason is that the compiler cannot find the library. Possible reasons this error occurs:

  • The library is not installed (see installation instructions above).
  • Incorrect folder location.
  • Wrong name folders.
  • Invalid library name.
  • You forgot to restart the Arduino IDE.

Below are solutions to possible problems

Incorrect folder location

The IDE only finds standard libraries and additional ones that are installed in the "Libraries" folder. Libraries that are located in other locations will not be initialized

The library folder should be in the root of the "Libraries" folder. If you create an additional subfolder, the IDE will not detect the library.

Note: in some online repositories, libraries are laid out with an additional level of folder nesting. Check this moment. The library files must be located in the first folder, without additional subfolders.

Not a complete library

You should not rename files in the library using capital letters, dash, etc.

Incorrect folder name

The IDE does not detect folders with certain characters in the name. Unfortunately, the IDE does not support dashes, which are generated in file names on Github. Therefore, after downloading the archive, rename the folder. The new name must not contain a dash. You can simply replace all the characters ('-') with ('_').

Invalid library name

The name you specify in the #include directive in your sketch must exactly match the name of the class in the library (case sensitive!). If the name does not match, the IDE will not connect required functions, classes, etc. In the examples that come with the libraries, the names are correct. So to avoid accidental errors, you can simply copy and paste them into your code.

Multiple library versions

If you have multiple versions of the library, the Arduino IDE will try to load them all at the same time. As a result, a compilation error may occur. So old or non-working versions must be deleted or moved from the library catalog.

Dependent Libraries

Some libraries depend on other libraries. For example, most Adafruit Graphic Display Libraries depend on the Adafruit GFX Library. That is, to use the first library you need to have the second one installed.

“Basic” libraries

Some libraries cannot be used directly. Good example, GFX Library. This library powers most displays from Adafruit, but cannot be used without a driver library for that display.

Forgot to close Arduino IDE

Don't forget that the IDE looks for libraries when loading. Before using a new one installed library, Arduino IDE needs to be rebooted.

Leave your comments, questions and share personal experience below. New ideas and projects are often born in discussions!