Import an Arduino multifile Project to PlatformIO


I have a problem with my Arduino project.

My Sketch has multiple files with multiple functions and of course a bunch of vars, many of them are global.

For the Arduino IDE it is not a big deal, I can use them in every file without the need of a header file and a prototype.

Now I want to use VS Code + PlatformIO because its many times faster and nicer to use and read the code. I imported the whole project from the Arduino IDE to PlatformIO and now the trouble begins.

Then PIO doesn’t find the global vars and functions from the separate files. Of course, I could reconstruct the whole code and make it like it should in C++ be, but I just don’t have the time.

Is it possible to make PIO handle the files/code like in the Arduino IDE (all global vars and functions are usable in every file)?

A big thanks for the help in advance.

Have you tried naming the main file with an .ino instead of a .cpp extension?

They are all ino files.

Then this does not seem supported.

Doing a main.ino of

void setup() {

void loop() {
    Serial.println("The var value is: " + String(someVar));

with second.ino as

int someVar = 10;

void some_func() {

results in

C:/Users/Max/temp/ino_test/src/main.ino: In function 'void loop()':
C:/Users/Max/temp/ino_test/src/main.ino:6:50: error: 'someVar' was not declared in this scope
     Serial.println("The var value is: " + String(someVar));

for me.

Only if I rename the second.ino to second.h and do a #include "second.h" at the top of main.ino, it works.

Linking .pio\build\uno\firmware.elf
Checking size .pio\build\uno\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]  10.6% (used 218 bytes from 2048 bytes)
Flash: [=         ]  10.2% (used 3284 bytes from 32256 bytes)
Building .pio\build\uno\firmware.hex
====================== [SUCCESS] Took 2.40 seconds ======================

So, you can try that…

Actually, this does not work in the Arduino IDE for me either with the original main.ino and second.ino files shown above.

Can you show an example of multiple ino files with global variables in the style that you do?


You are completely right, I didnt noticed I had a extra .h file with all the vars wich I included in the main.ino in Arduino IDE, thats why it worked there…xD