Arduino IDE: what’s in a library #10

Arduino IDE

Welcome back to our programming tutorial using the Arduino IDE. Today we will explain how to use libraries.

You can take a look at the previous chapters of the course here:

In computer jargon, a library is a collection of various instructions and functions. Libraries can be used within the codes and sketches created by programmers.

The advantage of using libraries is to avoid having to rewrite the same instructions, algorithms or functions (with attached definitions, declarations, etc.) each time, in order to facilitate development and maintenance options.

Many programming languages ​​include standardized libraries. It is a set of functions and / or data structures that allow solving the most common programming problems.

A library is made up of a pre-compiled code and a header file (with the extension .h) which represents its interface for users. A library collects a set of instructions, functions and procedures related to a solution related to that particular problem. The programmer can create new libraries.

The syntax for using a library is as follows:

Furthermore, the use of a library makes the code clearer and leaner, since instead of tens or hundreds of lines of code, the source has references to the functions of the library, accessed through a public interface. Libraries often contain very complex codes, and it would be difficult and inefficient to write that particular piece of code each time.

As soon as the library is defined, the modification is immediately operative for all the programs and sketches that call it. For this reason, maintenance work is also facilitated.

The Arduino IDE has an automatic library management system: just enter a keyword to indicate what you need to work on, and the IDE returns all the libraries present in the repository and capable of managing that given situation. As an example, simply follow what is shown in the figure, and after choosing “Manage Libraries” (or “Library Management”) enter the keyword “DHT11”: all the libraries capable of working with such sensor will be offered, and the user will choose (and possibly install automatically) the most appropriate one.

In the next article we will talk about the most famous libraries used in Arduino.

libreria

 

Follow us to keep yourself updated with the news!

Simone Candido è un ragazzo appassionato del mondo tech nella sua totalità. Simone ama immedesimarsi in nuove esperienze, la sua filosofia si basa sulla irrefrenabile voglia di ampliare a 360° le sue conoscenze abbracciando tutti i campi del sapere, in quanto ritiene che il sapere umano sia il connubio perfetto tra cultura umanistica e scientifica.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.