Fatal error: Arduino.h: No such file or directory

For some reason an error shows up every time I try to compile my code. Currently I am just starting out with arduino and I get this error every time. I tried the simple blinky program

 #include "Arduino.h"
void setup() {
 pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);  
  delay(1000);                       
  digitalWrite(LED_BUILTIN, LOW);    
  delay(1000);                       
}

and my platformio.ini file is

[env:nanoatmega328]

  platform = atmelavr

  board = nanoatmega328

  framework = arduino

Would appreciate if I could get some help. Also is there a discord for platformio?

Remove the folder C:\Users\<user>\.platformio\packages\framework-arduino-avr and rebuild. Your package folder probably got corrupted or downloaded incompletely.

There deliberately is no Discord server for PlatformIO because all information / help is intended to be on the publically viewable forum, not burried deep in thousands of lines of discord chat logs. See Is there a support chat channel for platformio?.

1 Like

I’ve deleted it but how do I rebuild?

Press the build button again.

You mean the run button right? I pressed it but the error is still there.

Run? That’s for debug. I mean the “build” project task.

Has the folder re-appeared that you deleted?

The folder re appeared but the error still persists.

Delete the folder again plus C:\Users\<user>\.platformio\.cache, plus C:\Users\<user>\.platformio\platforms\atmelavr. When you rebuild, it should show that it’s re-downloading the platform and framework packages. Does that appear?

Yeah that appeared and then it showed success.

I tried running the code again and same error.

That should be impossible.

Please show a screenshot of VSCode with opened code file and platformio.ini, and the error message visible.

You are somehow using an extension that attempts to build the source file locally with the g++ compiler for the local computer. This is completely wrong. You must trigger the firmware build via the project task “Build” (or “Upload” respectively), or via the toolbar through the PlatformIO extension. Not any other other plugin or menu.

Make sure that as installed extensions, you only have C/C++ by Microsoft, PlatformIO, Python and Jupyter. Other C/C++ build extensions will screw with the PlatformIO project.


You mean this right?

I dont have any other extensions except python, jupyter, platformio, c/c++ by microsoft, and pylance.

Yes exactly.

That’s weird, those build task instructions must come from somewhere.

Remove the .vscocde folder of the project, then Ctrl+Shift+P → Rebuild IntelliSense.

Does this behavior still occur of you execute the “Build” task then?

Yes.

I forgot to mention but I had completely uninstalled vscode following a stackoverflow tutorial and then reinstalled it because I was facing the issue but the issue didn’t go.

Try deleting the .viscode subfolder at (1), selecting the terminal tab at (2) and try re-building the project. What output is shown on the Terminal tab, even if VScode switches away from it. You should not editing anything in c_cpp_properties.json

Nope the problem is still there.

These are the two errors I am getting.

When you press the build button, is PlatformIO invokes and the build leads to “success”?

1 Like

That might be the case. But what is shown on the Terminal tab after pressing Build?