Real basic (stupid) Library question.(s).

Just started with Arduino and IDE. Lots of BASIC experience, (which might be the problem.)

I have been mostly using the Paul McWhorter Vids for my education and have no problem following and success with his sketches. (I am an old EE.) What I don't quite understand is the use of libraries. eg. in a typical sketch he will tell us we require a library. No problem. I include and using his instructions it all works fine.

He goes on easily typing in new function names say "lcd,setCursor (x, x, etc.) . OK, I assume that is a function from the lcd library? Or maybe from one of the other included libraries? Then he may put in several more functions with lcd.xxxx() functions. So the library must have several functions that I can use in my sketch? He inserts all these functions without any explanation of where they come from (like it should be obvious) . (Maybe I missed that lesson?)

  1. Does the "lcd." always indicate that it is a function from the lcd. library?
  2. I have looked at the lcd.hh and code this is not always clear to me.
  3. Is there a simple way to determine what functions that are provided in the particular library and how to use them?

As an example, in some libraries I to clear the lcd screen I have to use lcd.cls() another lcd.clear() or another lcd.clr().

When I see tutorial videos the educator type in these functions as if any dummy should know.. This dummy don't. :slight_smile:

Thanks.
Jim

The functions / methods are mostly listed in the .h file, in the class definition, in the public section.
Exceptions will be when the class inherits from other classes, when you will have to look at those class definitions

  1. Does the "lcd." always indicate that it is a function from the lcd. library?

Yes. The lcd is the name for an object of the type LiquidCrystal.

  1. I have looked at the lcd.hh and code this is not always clear to me.

It will take a while studying C++ but the code will be clearer as you use (learn) it.

  1. Is there a simple way to determine what functions that are provided in the particular library and how to use them?

I wish. If the author of the library takes the time to write good documentation* you are in luck. Otherwise you will have to examine the .h and .cpp files and the included example code. The .h file has the function declarations which should show the argument and return data types. The .cpp files have the function definitions which show the code that the function executes. The examples show how to use the functions in context.

See the documentation for the hd44780 library for LCDs.

Another thing to notice/know is that "lcd" is just the name your code assigns to the LCD object under the library's control.

lcd.print("hello, world!");

runs the print function of the LCD library on your LCD, named "lcd".

Everyone seems to just leave the name from the examples. I usually use a name like myLCD

myLCD.print("Jello Whirled!");

to clarify to myself that it is mine.

You may have noticed that the methods or functions appear in color, they are listed in the library somewhere as keywords to give you a clue that you are typing something meaningful.

a7

Most of the libraries come with lot of examples. If you install a new library, check all examples. If you do so, you will easily see, if your library uses .cls, .clear or .clr.

As others said, if you want to know more about the interface of the used library, see the .h files which often come with lot of comments also.

Most libraries come with example sketches. They are directly accessible from the IDE File menu after you install a library. Really good libraries also come with documentation. Tutorial makers are often technically very limited in knowledge (they often make really noob mistakes), but they know to look in those places, and at the website where the library is hosted. It's nice to know where the library source code is (in the 'libraries' folder of your sketch folder), but it shouldn't be necessary in order to use the library.

In some cases, the source code has been written with markup language, so that a doc file for all the functions can be automatically generated by some formatting tool like Doxygen. The file with that output becomes the de facto documentation.

sracing:
Just started with Arduino and IDE. Lots of BASIC experience, (which might be the problem.)

It shouldn't be. At least you are into the thinking.

He goes on easily typing in new function names say "lcd,setCursor (x, x, etc.) . OK, I assume that is a function from the lcd library?

Yes

Or maybe from one of the other included libraries?

No

. So the library must have several functions that I can use in my sketch? He inserts all these functions without any explanation of where they come from (like it should be obvious) .

Yes. It is obvious. It may even have more stuff than you actually need, but this is omitted when you compile you programme.

  1. Does the "lcd." always indicate that it is a function from the lcd. library?

Yes

  1. I have looked at the lcd.hh and code this is not always clear to me.

Don't look.

  1. Is there a simple way to determine what functions that are provided in the particular library and how to use them?

Each library should have programming examples included.

As an example, in some libraries I to clear the lcd screen I have to use lcd.cls() another lcd.clear() or another lcd.clr().

That's OK. Different libraries for different displays. You can also use different libraries on the same display. Further to Aarg, if you want to see a really good manual for a library, see Henning Karlsen's UTFT manual from RinkyDink.

Thanks to all. Very helpful. It's just not as easy as I hoped for when examples aren't included. A really neat ap (or discipline) would be that a simple remarks section in the beginning of each library that includ a list of all that libs functions. Thanks again.

sracing:
Thanks to all. Very helpful. It's just not as easy as I hoped for when examples aren't included. A really neat ap (or discipline) would be that a simple remarks section in the beginning of each library that includ a list of all that libs functions. Thanks again.

That's what programs like Doxygen do (well a little bit better), as I mentioned. Really, although a .h file should have internal documentation, it should never serve as a replacement for proper user documentation. This should be a separate file in human readable format like txt or PDF.

It's hard to imagine why any library would not have some examples, as normally, these would be needed by the library author to test the library.