PlatformIO Community

How do I add a library using lib_deps?

I know this is a really noob question, but I have been bouncing around between various tutorials and trying to read the documentation. How do I add a libray to a project using lib_deps option?

The tutorials I come across on youtube, show that there is a way to download a library directly into my project, how ever when I open the library manager to download the library, I only have the option to download to global storage.

Then once the library is downloaded into the project, the INI file is tweaked to use the library when the program is complied.

Is there a straight forward instructions for adding a library to a project and setting up the dependencies?

I am using visual studio code with PlatformIO

Have you read

1 Like

In a nutshell:

  • Go to the library registry - either via your web browser, or via the libraries view of PIO Home
  • Search for you library, and open its information page
  • Click the installation tab once you’ve found your library, and copy whichever version of the lib_deps entry you want to use - ID, by name, by name and version, etc. Choose only one line.
  • Open your platformio.ini file, and add that reference under lib_deps (adding it if missing), with a single library reference per line if you have multiple libraries to declare.

i.e. for this project, I have several libraries, and I chose to reference by ID and specify specific versions of the libraries to be used, and then used comments to remind me what id related to what library.

lib_deps = 
    1@2.3.5    ; OneWire
    38@1.6     ; LowPower
    54@3.8.0   ; DallasTemperature
    433@1.3.3  ; RF24
    1002@1.0.5 ; elapsedMillis
    1976@1.1   ; SerialCommands
1 Like

Yes, I have read the documentation multiple times. I am still having trouble following it.

Okay, if I am following your example correctly, I don’t need to actually download the library first. I just need to set up the dependency in the ini file. Then when I complied my program, the library will be downloaded.

1 Like

Spot on. If you declare libraries via lib_deps, PlatformIO will automatically try to download them when you compile your program if they are missing.