Hi, I have been mainly using the arduino IDE for constructing my projects and yesterday moved to vsscode and platformio, which I have found to be brilliant. I’ve read a lot of documentation, but I’m struggling a bit with workspace, folders and projects.
In my arduino ide world, I use Github to version control the source code for my projects and each project has a folder intialised as a git repo, containing the ino and gitignore.
So today I’ve had some great help to get a debug environment working for my mega2560 boards and I configured the platformio.ini file accordingly, using a led blink test sketch.
Next, I thought I’d import one of my arduino projects from the local git repo and I did that from platformio home ‘import arduino project’. However, it’s apparent that the source code is being saved elsewhere (not in my git repo ) and I’ve verified that by adding a comment to the source, saving it and then inspecting the file in the git repo. Also the changes I made to the platformio.ini are no longer there (probably not lost I’m guessing - I have a copy anyway).
So I think I’m missing something to do with workspace and project organisation in platformio/ vsscode.
Indeed. By using “Import Arduino Project” PlatformIO will allow you to select a folder with a .ino file and select a board. It will then create a new folder in which it initializes a standard PlatformIO project with the given board, plus that .ino file as initial source code.
That folder will by default be created in the user’s “Documents” folder in “PlatformIO/Projects”. It will not modify the original directory.
Source files which are supposed to be compiled should be in src/, include files (.h) which are not compiled can go in include/ (or src/), lib/ can be used as folder in which further library folders can be stored that the project needs locally, and test/ is for files regarding unit testing.
The pio init command also says that.
>pio init -b uno
The current working directory C:\Users\Max\Desktop\test will be used for the project.
The next files/directories have been created in C:\Users\Max\Desktop\test
include - Put project header files here
lib - Put here project specific (private) libraries
src - Put project source files here
platformio.ini - Project Configuration File
All of these foldernames and paths can be abritrarily reconfigured (docs) using platformio.ini directives.
So using that it would e.g. be possible to have a folder structure where it’s just one .ino file and the platformio.ini in one folder. But that’s not standard configuration. Example:
A folder contains the platformio.ini:
; redirect src/ dir from "src/" to "here"
src_dir = .
platform = atmelavr
board = uno
framework = arduino
The project name is just the folder name. Can be abitrary.
In VSCode, you can right-click on the folder and select “Reveal in explorer”. Then in VSCode you should right-click on the folder again to “Remove folder from workspace”. Then go ahead and rename the folder, then use PIO home with the “Open Project” button to import the folder again.
(That procedure because with VSCode open you can’t just rename the folder directly because files are opened in there – also PIO will look for this folder after restart and get a little confused if it suddenly isn’t there anymore, so a clean unload-reload is good)