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