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
- Open a new instance of Visual Studio
- Select the Arduino Library Project Template, and click [Next]
- Enter the name of your library
- 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]
- Ensure the "Place Solution and Project in the same Directory" is checked
- Click [Next]
Your library project will now be loaded, with the
library.properties file, and your
LibraryName.h created in the
The Library.properties 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
url details to suit your purpose.
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
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.
Make sure you amend the location of where to add the file to be beneath the
src folder, or a sub-folder below the
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:
- Right Click the solution in Solution Explorer
- Click Add Existing Project
- Locate your Library Projects' VCXPROJ and click [OK]
Then you will need to add a reference to it from your Sketch project:
- Right click your Sketch Project
- Click Add Reference
- Select the Solution tab on the left
- Check the box next to your library project name and click [OK]
Managing Libraries with Library Manager
Arduino Shared Cross-Platform Code And Library Development
[Advanced] How to Automatically Pre-Compile Library Archives