Hey,
I struggle also on this question and will try to give different âsolutionsâ (none of them are perfect). The question is: âOne platformio.ini for multiple projectsâ . One may consider that âprojectsâ here is the actual projects you create in platformio. Letâs enlarge the âprojectâ concept to something more general. You want to have different projects/scripts that maybe unrelated but sharing the same library to explore different modules, different way to realize your goal with your microcontroller. In the past, we did âLed_Blink_1.inoâ and then if we have a new âprojectâ: maybe the Led will blink each five seconds, we create un new file: Led_Blink_5_Sec.ino" etcâŚ
But now, since we normally all know that we should avoid global library in platformio, that means that each time, we create a new âprojectâ, we need choosing the name of the project, the board, then install all the libraries locally in the libdeps folder, then one may want to add a git repository, sync with github, put this new project in a VS code workspace etc⌠all those actions take actually a long time compare to the time where we just created Led_Blink_2.ino and upload it: right?
And itâs why tonight, as a newbie, i passed two hours on the forums to find a solution because Iâm lazy and itâs definitively a too long workflow to test and upload quickly my âLed_Blink_2.inoâ. So I will propose three different solutions. One is correct, the two others may be considered as ugly but there are faster.
Solution 1:
as mention a lot of time: one should go with âlib_extra_dirsâ . The author of the question asks for an example. And I was also looking for an example. And I didnât find an example because itâs quite easy. You create your new project but you donât add manually each time each library by using the library manager. You simply add this line in the plaformio.ini:
lib_extra_dirs = F:\Documents\PlatformIO\Projects\Previous_Projects.pio\libdeps\esp32dev
Here itâs an absolute path to a previous project where I had already installed each library with the library manager. And itâs works well even if itâs not very beautiful. Alternatively, one may just copy the content of the folder that appears for me like this:
[Sorry, i can only put one image because itâs my first post, thus i removed this one]
.
And paste it in a new folder. For instance, C:\My_ESP32_Library
then just change the path in the platformio.ini for:
lib_extra_dirs = C:\My_ESP32_Library
And it works. you donâ have to install again and again all the libraries for the new âLed_Blink_24.inoâ. It works but itâs still quite slow: you still need to create a git repository etcâŚ
itâs why I propose the solution number 2 (quite ugly): the way I was actually working before trying to find a better way.
Solution 2
I just create a new git branch for each ânew projectâ : thus I have maybe more than 15 branches in the same repository. Sometimes those branches are quite related to each other, sometimes, itâs just a branch to quickly test a new sensor/module before incorporating it to the current main project. Thus no need to create a new project, adapt the path in the platformio.ini, change the baudrate etc⌠But normally, git branch are not supposed to represent different projects. And later, it may be harder to find quickly a good script if itâs hidden in a git branch.
[Sorry, i can only put one image because itâs my first post, thus i removed this one]
Solution 3
Here is the last solution: the solution that I just found. I keep solution 1 but add somethings else. Thus I create a new project, I change the path to the directory containing already all the libraries to avoid installing them each time, and when I need âBlink_LED_48.cppâ, I donât do that again, I just actually create a new file!! âBlink_led_48.cppâ!! and I cut and paste the previous âmain.cppâ in a folder specially created for that, that I called Previous scripts (watch this folder in the image below). What is important is that it should have only one file with the setup() and loop() function in the src folder to avoid compilation error. This file doesnât not need to be called âmain.cppâ, it looks like one may rename it as he want. Thus, I can make a lot of tests with a lot of files that go to the previous script folder when I need to test a new one. And if I want to take it back again, i just exchange their place. All the scripts are under source control and nothing prevent me to create a new git branch if a change is clearly related to the main project.

Hope those ugly solutions helps. Maybe one of you have even a quicker way to proceed?
Cheers,
Viafx24