Question about libraries

"hello, good morning. i have a question related to library. my guider told that you should learn to modify the library, what is the purpose of modifying the library?"

Often novice Arduino users treat libraries as black boxes. But they're not. It's just more C++ code (well sometimes C or assembly, but usually C++), just like your sketch. Part of the reason is that you can easily install libraries without ever seeing their files and since you can't (easily) edit library source files using the Arduino IDE.

The first benefit of learning to modify a library is that it will show you the code hidden behind that API you've been using.

One good way to learn in programming is to make some changes to existing code and then checking whether the result is as you expected so learning how to modify libraries could help you learn how to write your own.

Learning to write libraries is a very useful skill for the Arduino user.

A library allows you to share code between multiple sketches without needing to make and maintain multiple copies of that code.

A library is the best way for you to share code you wrote with the online community in a form that is generally useful.

Not all library code is perfect. Learning how to modify libraries will allow you to try to track down and fix bugs you may encounter when using a library.

This skill will allow you to participate in the development of the many open source Arduino libraries this community thrives on.

thank you, for your replay. sir, i want some basic steps or sujjestion to modify the library(means which file should be read first in the library) like that.

"please any one tell about (1) how to modify the libraries.
(2) which file should be read in libraries.
i wish to understand in detail with steps"

The first thing is to determine where the library is. This is not so simple as you might think because you might actually have multiple versions of a library of the same name installed on your computer. If you are modifying one library and compiling another you will have a lot of confusion.

If you do File > Preferences > Show verbose output during: Compilation (check) > OK you will be able to find the library path in the output in the black console window at the bottom of the Arduino IDE window after compiling your sketch. You will need to scroll the window up to see it all.

An alternative to the above is this:

  • File > Examples > select any example of the library you want to find
  • Sketch > Show sketch folder

This will open the exasmple sketch folder. Navigate up two folder levels to find the root of the repository. This technique can be useful because the libraries bundled with hardware packages you install via Boards Manager will be in a folder the operating system tries to hide from you. Of course this requires that that library includes example sketches.

Some libraries will have their source files in the root library folder (1.0 library format). Other libraries will have the source files in a subfolder named src (1.5 library format). Additional source files may be found in subfolders.

To view and edit library source code you will need a good quality text editor. There are many good options. My personal preference is notepad++ but you are welcome to find one you like. Just make sure to not use Windows Notepad.

The header files have the .h file extension. These files typically contain the function prototypes. The implementations of the functions are typically found in files with the extension .cpp or .c. You may also find header only libraries with all their source code located in the .h file.

This is a good tutorial for writing libraries:
I actually think that may be a better way to get started with libraries than jumping into some very complex code but both skills are useful.

You can find some useful information in the Arduino 1.5 library specification:

Now get to it!

"thank you sir for your suggestion. i will try in that path"