VS Arduino
Visual Micro >> Project Guidance >> Workflow for creating a new Arduino Library?
https://www.visualmicro.com/forums/YaBB.pl?num=1617070855

Message started by Zenra on Mar 30th, 2021 at 2:20am

Title: Workflow for creating a new Arduino Library?
Post by Zenra on Mar 30th, 2021 at 2:20am
I’ve used Visual Micro for years but only recently taken an interest in using the environment to author libraries.  I am having trouble, though, understanding the usefulness of the “New Arduino Library” option creating a new Visual Micro project in VS2019.  When I start a new solution, or add a “New Arduino Library” project to an existing solution, I get a project with *.h and *.CPP files, which is fine, but with no configured references or means to build the project. I can add another project to the solution to test the library under development, but even after including the library in that test project Intelli-Sense doesn’t work in the library source files, which is very frustrating.

I assume that I must be mis-using the new library project option, so am looking for instruction for using it properly.  I like working in Visual Micro a lot, and as the scope of the projects I work on continues increasing to include ESP32 boards and more complex applications I would really like to leverage ways to share code modules and build libraries in this environment, for all the usual reasons. I will appreciate advice on workflow, directions or explanation for how to develop Arduino libraries using Visual Micro, etc.

Thanks for a great tool, and for all the experience and expertise shared here.

Mitchell

Title: Re: Workflow for creating a new Arduino Library?
Post by Tim@Visual Micro on Mar 30th, 2021 at 2:34am
Thanks for the question. There are a few points that might help you understand but feel free to ask for more info

1. An Arduino library is not a program, the library code can be referenced/used from an arduino program.

2. If your new library is created in your arduino "sketchbook/libraries" folder then the library will be accessible to all arduino ide and visual micro projects. After creating the library in the sketchbook folder, I suggest you click the "vMicro>General>Reload Toolchains" or re-Start the IDE. The arduino sketchbook/libraries folder is usually "documents/arduino/libraries"

3. In Visual Micro, if you have created a library outside of the arduino sketchbook/libraries folder and it is included as a project in a solution that also includes one of more arduino projects. Then for the Arduino project you can right click "References>Shared". The library will be displayed in the list, you can check the checkbox to include it in your arduino project. By adding a Reference to the library this way you can place libraries anywhere without being restricted to the official arduino library locations.

4) In all cases libraries are #included in code, when required, using the normal arduino library include syntax which does not contains paths. For example:- "#include <MyLibHeader.h> as opposed to #include <../foo/MyLibHeader.h>

tip: If you use the "Clone" facility on the Visual Micro "Add Code> Library" menu, then you will be able to add a standard arduino library. Visual Micro will create a shared library project for the library you select and Visual Micro will  add the "Reference" described in 3). It might be a way to see a working example.

Does this help?

Title: Re: Workflow for creating a new Arduino Library?
Post by Zenra on Mar 30th, 2021 at 12:59pm
Tim,

Thank you for the fast and thorough reply.

I think I understand well enough how Arduino libraries work and thanks to your description how VM handles them.  For me, your item 3 made the difference: Adding a reference to the library under development (which I placed in the same libraries folder with all the other libraries I've installed) as a "Shared Project" to another project I set up as a test bed for the library under development solved all the issues (e.g., duplicate modules found during linking, etc.).  I like this project structure because it allows me to develop the library in situ with full intelli-sense support and not need to have to manually copy the library files from a development folder to the Arduino libraries folder every time I make updates.

Thanks again for the help!

Mitchell

Title: Re: Workflow for creating a new Arduino Library?
Post by Tim@Visual Micro on Apr 3rd, 2021 at 9:54pm
Excellent. Your solutions sound great.

fyi: One point I didn't mention but of no consequence. Right click a shared library should show a Visual Micro "Publish" menu item. That copies a library back to the sketchbook/libraries folder.


Title: Re: Workflow for creating a new Arduino Library?
Post by Zenra on Apr 8th, 2021 at 1:53am
Tim - I did not know that but am happy you shared the tip - will almost certainly use it under the right circumstances.

VS Arduino » Powered by YaBB 2.6.12!
YaBB Forum Software © 2000-2024. All Rights Reserved.