How do you make a default library?

I can make libraries, no problem. But to use them I have to include the library, eg.

#include <Timer.h>

But some libraries don't need including. For example you can do:

Serial.begin (9600);

... without including the Serial library.

So what steps do you take to make your libraries "just work" in the IDE without having to include stuff, particularly if it is useful things like streaming, or timing, that you use every day?

They are included in the real main, that is in the core folder, probably the #include is in fact inside the WProgram.h

Modify the core. The source files go in {ArduinoRoot}\hardware\arduino\cores\arduino. Modify WProgram.h to directly or indirectly include your header file(s).

I see, modify WProgram.h.

Thanks both of you.

Probably not a good idea. The next update will have its own wprogram.h (without your modification).
I'd advise just going ahead and typing in the #include for your library.

Plus you will confuse anyone trying to use your library too. It's best to reside your libraries in sketchbooks\libraries and have the IDE add library like other contributed libraries do.

Don't worry, I won't do that. I can see great potential for confusion.

User contributed libraries are great things and can save lots of time for quickie simple programs. I advocate using them and use them myself. However while the use of (contributed) libraries can make life a lot easier, if I'm writing code for pay I tend to avoid them altogether for several reasons.

  1. All too often I find bugs in user contributed libraries and modify them.

  2. At code delivery time I want to give my customer everything he needs to duplicate my setup exactly as it existed when the code was written.

What I usually do is copy the libraries into the sketch folder itself. Almost always I change the filenames by prepending my initials. I ALWAYS do this plus add a rev number to the filename if I modify the file in any way.

At delivery time I give the customer media containing the entire sketch folder and the installation file for the Arduino IDE version used during development. It's simple then for him to reproduce my setup for the inevitable maintenance issues that might arise.

The downside of my approach is that my sketch folders tend to have LOTS of files. Most of my projects for hire are quite large and I tend to use a lot of classes - each with its own .cpp and .h file. This pretty much makes the IDE a pain. It just doesn't handle 40 or 50 files very well. For code editing I use an external editor (UltraEdit Studio) which handles projects with a huge number of files easily. I only use the IDE as a convenient tool for compiling and uploading code.

Just beware that some library owners don't want you make money out of their libraries, I'm one of them :slight_smile: They spend time (yes some have bugs but your code can't be bug free from the very start, plus they don't get paid as you do) and if you take their work and sell them, you should look at their permissions.

Educational and personal uses are most often free. If you sell software then why don't you pack all those codes in libraries, beats 40 files open at one time. Every library saves at least two tabs, a .cpp and a .h

The point for libraries is once the library is written, there is no point to see its internal code anymore.

Oh, be assured I do look at the permissions -- and follow them.

As to when code goes to (my) libraries - not when it is written but rather when it is written and thoroughly tested. :slight_smile:

I do that too. I take my original library, add them to my test folder and change .h file names so I'm not including the original library but the local one being modified. After this is done, rename the .h back and copy them to library folder and rename the test sample code.