Error while building an older Project which could former be builded without errors

Visual Studio Code:1.56.2 PIO:Core 5.1.1 Home 3.3.4
I do not know the former versions.
All older projects based on Arduino Nano (nanoatmega328) can not be builded without error:
Example:

 #include <Arduino.h>
          ^~~~~~~~~~~
compilation terminated.
*** [.pio\build\nanoatmega328\src\CreateSound.cpp.o] Error 1
*** [.pio\build\nanoatmega328\src\DebugOutput.cpp.o] Error 1
src\GetCommand.cpp:1:10: fatal error: Arduino.h: No such file or directory

I created an empty project with PIO and compiled it.
Same error.

I have also older project based on ESP12F and STM32 these projects can be compiled without any errors.

None of the solutions i found for this problem worked.

My solution:
Back to the roots. rename *.cpp in *.ino. flatten the directory to one. Open Arduino ID start compilation and results in no errors. It worked.

But i am not happy with this solution. And i am also dissapointed from PIO (or the combination with Visual Studio Code).

Has anybody a solution?
What ist necesarry to preserve a project which can later be compiled the same way?

So far, my bitbucket projects based on git must be trash or i am a real PIO dummy.

Sometimes changes between older and newer versions might need a “clean” before a new build. Did you try clicking on the “build clean” icon on the PIO toolbar? It looks like a dustbin/trash can. That often fixes things.

Another solution is to delete the entire .pio directory inside the project’s directory, in case the “build clean” didn’t get rid of enough old stuff.

I created a new project for the Nano and generated the following platformio.ini file:

[env:nanoatmega328]
platform = atmelavr
board = nanoatmega328
framework = arduino

For my source, in src/main.cpp I have this:

#include <Arduino.h>

void setup() {}
void loop() {}

This compiles and runs perfectly for me. What is your platform.ini showing please> and if possible, can you post your source code as well? Thanks.

Code can be pasted between three backticks to get correct formating is to avoid losing characters, as follows:

```
Your code here...
```

This are not the same as the single quote character, in case your browser shows them as similar. :wink:

Cheers,
Norm.

I cleaned the project not only one time.
Also I deleted the directory .pio and .vscode

This is the platform.ini file:

; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; Redirecting...

[env:nanoatmega328]
platform = atmelavr
board = nanoatmega328
framework = arduino

This is also the src/main.cpp

 #include <Arduino.h>
 
 void setup() {
   // put your setup code here, to run once:
 }
 
 void loop() {
   // put your main code here, to run repeatedly:
 }

This is the result I get

If i change the framework-arduino-avr (which does not exists) to framework-arduinoavr the .vscode faults disappears. But the include error is still there.

Try to do a complete update and re-initilization.

In a CLI do

pio upgrade --dev
pio platform update atmelavr
pio init --ide=vscode

then retry building.

If that does not work, the toolchain / framework files may be broken and you need to delete them in C:\Users\jus66\.platformio\packages\framework-arduino-avr to trigger a redownload.