How to Create an Arduino Library

If you want to create your own Arduino Library, Visual Micro has all the features you need to get started right away.

Why Create a Library?

Libraries allow you to encapsulate a set of functionality (e.g. driving a stepper motor) in a single module, so it can be added to multiple projects easily, from a single set of source code.

It also makes it very easy to share with the whole Arduino community, so everyone can benefit and contribute to your innovative idea.

Create the Basic Library

  1. Open a new instance of Visual Studio
  2. Select the Arduino Library Project Template, and click [Next]
  3. Enter the name of your library
  4. Set the location to SketchbookFolder\Libraries (e.g. C:\Users\vMicro\Documents\Arduino\libraries)
    [This ensures that the Arduino IDE will have access to the library as well]
  5. Ensure the "Place Solution and Project in the same Directory" is checked
  6. Click [Next]

Your library project will now be loaded, with the file, and your LibraryName.cpp, and LibraryName.h created in the src folder.


The File

This file ensures that your library can be correctly identified in the Arduino ecosystem, and all properties are documented in the Arduino 3rd Party Hardware Specification.

All basic properties are auto-filled, however you will likely want to amend the sentence, paragraph and url details to suit your purpose.

Note IconNote:

If you are designing your library for specific boards/chips then ensure the architectures option is set correctly (e.g. if this is for AVR chips only, set it to architectures=avr)


Adding Code Files

You can add more code files to your Library by right clicking on the project in the Solution Explorer and clicking Add > New Item.

Note IconNote:

Make sure you amend the location of where to add the file to be beneath the src folder, or a sub-folder below the src folder.

Note IconNote:

To ensure your library works correctly, you must have the LibraryName.h in the src folder. Then use #include statements in the LibraryName.h to include any other files from the subfolders, making the LibraryName.h a defacto interface to your library.


Using Your Library

Below is a quick summary of adding Libraries, with all detail about adding Libraries to your sketch available on this page

From the Sketchbook\Libraries Folder

If you have put your library into the SketchbookFolder\libraries folder, you should be able to select it from the vMicro > Add Library > User Installed Libraries drop down list.

From Another Location

If you have saved it to a different location, you will need to add the library project into your solution:

  1. Right Click the solution in Solution Explorer
  2. Click Add Existing Project
  3. Locate your Library Projects' VCXPROJ and click [OK]


Then you will need to add a reference to it from your Sketch project:

  1. Right click your Sketch Project
  2. Click Add Reference
  3. Select the Solution tab on the left
  4. Check the box next to your library project name and click [OK]


Useful Links

Managing Libraries with Library Manager

Arduino Shared Cross-Platform Code And Library Development

[Advanced] How to Automatically Pre-Compile Library Archives