Particle libraries

I am using visual studio to do my coding. I am having the most difficult time managing the libraries and getting them imported into the project correctly. The process I am currently using is that I enter the command line within visual studio. I create a directory in the library folder. Move to that directory and do a “particle library create”. I then must fill in the version number and creator information, which I complete with nonsense. I then take the actual library files that I get from Adafruit or elsewhere and move those files into the library folder. This seems like such a difficult process that I figure I must be doing something wrong. Not to mention that sometimes when the library has a folder structure within it the program still does not work. I do not want to use the web interface even though it seems like it would be easier. I would appreciate anyone pointing me in a better direction. TIA.

Hi there. Below is a link to a video showing the creation of the library folder by installing an existing library.

In general, it is easier to explain if you begin by creating a new project. Then, add an existing library. Configure for device. Clean project. Build. Flash.

To clarify a bit, I use the keys SHIFT, COMMAND, P to bring up the command line.
I choose “Particle: Find Libraries” first to verify the library is available.
Then, choose “Particle: Install Library” to install it. Your library folder will automatically be created in the project and the particular library included there, as in the video.

Importing is a little different. To switch between your projects, you need to prepare the existing project to be imported first. To do this, on a Mac, I change my existing “lib” folder, in the “Finder” to “lib-old”. Then, switch back to VSC and perform the import: “Particle: Import Project”.
Hopefully, you will see a new folder “lib” created with your intended library included within, in addition to your “lib-old” folder and it’s contents.

On import, if you forget to rename the folder above, you might get this error:

There is a file called “” in your project which is updated when you install a library. It tracks the name and version. On the next import, this library (and version) will be automatically placed in your project.

Hope this helps!

1 Like

Thanks for the reply. I don’t have a problem installing a library that I can find. It just seems like the ones I need are generally not in the particle library. When you say to switch between your projects, do you mean when switching libraries. Do I simply install all of my non-standard libraries in every project by reusing the “lib” folder each time and gradually accumulating libraries? What is VSC? When you say “finder” what does this mean? Thanks again for the reply. You have at least convinced me that this is about as horrible as I thought. In arduino I don’t have any of these hassles.

Yes, I understand the issues you are facing, believe me. :wink:
Are you creating firmware for Particle devices? If so, which ones? If not, well, this resource is for folks interested in developing on Particle devices. The existing libraries available are intended to be run on them.

Nope, you can use symbolic links to the respective library folder placed in your project’s lib folder.
When you actually “port” a previously unavailable library to work with the Particle toolchain you can contribute them to the Particle Library Repository (private or public) and from then on you can use it with more ease :wink:

VisualStudio Code which is the engine driving Particle Workbench.

“Finder” is the MacOS version of Windows’ (File) “Explorer”

I am working on a project for the boron.

Thanks for the explanation. I should have known VSC. I’m a dummy. Regarding the links to the libraries I keep getting errors No such file or directory when I have a path for a library. For example I want to use imumaths.h that is in a lib folder called utility. When I type #include <utility/imumaths.h> I get the no such file error.

As @ScruffR said, you can place your files in the “lib” folder. The libraries you put in this directory need a certain structure. Here is an example to follow which may help.

Install the “movingAvg” library, even though you don’t need it, into your project. Your test app directory might then look like this:

Next, add this line to your app source to finish:

#include <movingAvg.h> //
//  v(2.1.0)

Your library new library needs to follow this structure. Try manually placing the files in your “lib” directory so it looks like so:

The “new” library directory name and the “new” library source files (.h & .cpp) need to match. The source files need to be within a “src” folder, as shown.

Next, add this line to your app source to finish:

#include <imumaths.h>                 

You will also need to: Configure for device. Clean project. Build. Flash.

Thanks. That all makes good sense. So, I take it that I cannot have a library where I reference it in a subfolder?

I think you can. But, I was trying to successfully do it before replying. I will keep trying. Meanwhile, here is a link to documentation about it:

If you want to use a non-conformal library (not featuring a file and not adhering to the structure) you’d need to place all the relevant files inside the src (directly or via link) folder.
However, pre-compiled libraries will probably not work.

1 Like

I added application note AN038 Libraries that includes more detailed technical information on using libraries, in particular with Workbench. Hopefully this will help!


Thank you-all for the explanations. Using non-standard libraries in VSC with Particle has always been unclear to me. I wish it was simpler. [ScruffR], you mention that one can contribute libraries that have been adapted to the particle toolchain. How would one do that?

Found it. Instruction for uploading modified/created libraries is at Firmware Libraries | Tutorials | Particle
Thanks for the lead rickkas7

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.