Undestanding libraries and how to choose/use them

I am an enthusiast of Arduino. I have create some softwares (WEB radio, infrared remote control, automation of pump systems and so on...) but I still have a question: suppose I need use VS1053 audio board. Several libraries are avaliable. Other example: 74HC595 shift register have several libraries also. LCD displays also... but I do not know the resources of each library, so I have doubt which one is the better according to my needs. How can I discover the "core" or contents of a specific library, how to use the methods/classes? What courses I must to do to learn libraries? Note: I do not want to create a library; just look inside them and evaluate. Thanks in advance.

Totally easy to 'look inside' just include the header, then rt click and click 'Goto Definition' A (locked) tab will appear in the IDE and you can look at all the details.
Also, many have information and even Wiki's on github. Usually when you find a library (no need to install yet) there will be a 'more' link. Click it and a browser window will open at the github site.


Screenshot 2024-08-12 at 16.11.36

Hi @ronoelvb.

The primary method Arduino library developers use to document the usage of their libraries is through example sketches. After you install a library in Arduino IDE, you will usually find a list of examples for the library under the IDE's File > Examples > <library name> menu (where "<library name>" is the name of the library). These examples will demonstrate how you can use the library in your sketches. You can upload the example sketches of interest to your Arduino board to try it out, and modify the example code to experiment with using the functionality of the library.

Beyond that, the availability and quality of documentation differs from one library to another, according to the whims of the library's authors. Some don't bother to provide any documentation at all. Others provide comprehensive and high quality documentation.

The documentation might be published at a variety of locations. In general, you will be able to find it by searching the Arduino IDE Library Manager for the library name, scrolling down through the search results until you find the entry for the library, then clicking the "More info" link you see there. This will open a URL provided by the library author in your web browser. You might find the documentation at that page, or a link on the page that leads to the documentation.

The documentation for the official libraries maintained by Arduino is published here on the Library Reference:

All the thousands of 3rd party libraries from the Arduino Library Manager are also listed there. Although Arduino does not publish documentation for these libraries, their page in the listing contains a link that will take you to the library's project website, where the documentation might be published.

What is always available even when the library author didn't bother to provide any documentation, and guaranteed to provide accurate information, is the library source code. You can study the source code to learn the API it provides, as well as how it is implemented. The library source code is stored on your computer so you can open up those files in any text editor. You can also find the source code repository for the library online, which is sometimes more convenient to use as a reference in the context of discussions with other community members online. The "More info" and library reference links I mentioned above will usually take you to that repository.

1 Like

If these are long term projects place the libraries in the sketch folder and use " in place of the angle brackets. In the future if the library is updated and is not compatible with your code you will never know as you have the unchanged working library right there. Disk space is inexpensive.

Hi sonofcy. Amazing! I have never see this resource. Help me to improve my knowledge. But is not functional for all libraries. I will use. I am not a professional programmer. I have made about 4 different courses about Arduino, C++, POO but I am still in doubt how to use classes, their sintaxes. I know, is a lack of knowledge, I am still looking for an "ultimate" course to learn... thank you very much!

Hi ptillisch. As a matter of fact, I have used all resources you have give. Mainly, pieces of code from the world! I am not a professional programmer. I have made about 4 different courses about Arduino, C++, POO but I am still in doubt how to use classes, their sintaxes. I know, is a lack of knowledge, I am still looking for an "ultimate" course to learn... thank you very much!

Hi gilshultz. I did know this. So, inserting an specific library in the sketch folder instead the "standard" folder on Arduino IDE AND using "library" instead , will never be automatically updated? That happend with me when I made a code for a Internet clock and insert audio (cucoo) and another project of mine related to infrared controller. I "burned my brain" to solve them because, from nothing, did not work anymore... thanks a lot.

I'm not sure I understood correctly what you mean by this. If the lack of functionality is technical in nature, you can provide a detailed description of the problem and we might be able to provide assistance to overcome it.

I don't know about courses, but I found this tutorial to be very useful when I was starting with Arduino:

https://cplusplus.com/doc/tutorial/program_structure/

This is a general C++ tutorial, not specific to Arduino or embedded systems; written with the assumption that the reader is running the programs on a PC. This means that it contains some information that is not relevant for targeting a microcontroller. In order to follow the tutorial, you have to have some intuition about which parts are not relevant and the ability to either skip over them or mentally substitute the equivalent relevant information.

I personally didn't read it end to end, but rather selectively studied the parts of the tutorial for subjects I thought immediately useful, returning to it as I needed to learn about other subjects. I think that approach makes it more palatable to a casual Arduino hobbyist, but if you are looking for a "course", then you might prefer to go through the whole thing at one time.

You are welcome, that is what we are here for.

I have tested some libraries and, some of them, I got no answer. But it is OK, because it is a new way to consult...

About the link above, I am studying and became very useful. Now I undestand some "odd" commands. Thank you.

Thanks for the clarification.

The "context-aware" features (e.g., autocomplete, "IntelliSense", suggestions, "Go to Definition") of Arduino IDE only work for objects from a library after one of these events occurs following the time of the addition of the #include directive for a library's header file in a sketch:

  • The sketch is opened in Arduino IDE
  • A different board is selected in the Arduino IDE menus
  • The sketch is compiled

So when you encounter this problem, try this:

  1. Select Sketch > Verify/Compile from the Arduino IDE menus (or click the "verify" button if you prefer).
  2. Wait for the compilation to finish.
  3. Try using the "Go to Definition" feature again.

In case you are curious to know the boring details behind why Arduino IDE has this behavior, I'll provide an explanation below. If you aren't interested, you are welcome to skip reading the rest of this post.

The reason for the deferred awareness of objects from libraries compared to the awareness of other objects in the sketch (which is updated after every edit to the code) is that the awareness of library objects is dependent on a process known as "library discovery", where Arduino IDE scans all installed libraries for a header files matching the #include directives of the sketch program and picks which libraries to add to the compiler's "search path". That "library discovery" process is somewhat resource intensive. The overhead of that resource usage is insignificant when it is done as part of the occasional manually triggered compile operation, but more significant when it comes to the continuous processing that is done to support the "context-aware" features. The developers decided to change to this "deferred discovery" approach for the "context-aware" feature support in response to user complaints that the previous approach was too heavy for lower spec PCs.

My friend, finally I am "enligthened" about classes, members, objects and so on! I read the tutorials from cPlusPlus.com and now I have where to learn. That is exactly what I am looking for. In few days I will be on vacation, so plenty of time to study.
And yes, I read everything you wrote. Top TEN. Thanks again!

You are welcome. I'm glad if I was able to be of assistance.

Regards, Per