Cannot open source file "Arduino.h"

Great stuff. That will explain the problem. I’ve upgraded to dev. compilerPath is:

"compilerPath": "/home/greg/.platformio/packages/toolchain-atmelavr/bin/avr-gcc",

Appreciate the help.

1 Like

I also have this problem. Its only cosmetic as the project builds fine, but it is annoying.
I only noticed it when I created a common library to use across all my projects.
I observe the following:

  1. My class file <download.h> finds <Arduino.h> after about 5 sec.
  2. Then when I click over to the <download.cpp> tab, the <download.h> tab turns red and intellisense complains about line 1: #include <download.h> .
  3. When I click back to <download.h>, I see intellisense complaining about #include <Arduino.h> again for 5 sec, then finds it again, and the squiggles disappear.

OS: Windows 10 64bit

VSCode Version:
Version: 1.56.2 (user setup)
Commit: 054a9295330880ed74ceaedda236253b4f39a335
Date: 2021-05-12T17:13:13.157Z
Electron: 12.0.4
Chrome: 89.0.4389.114
Node.js: 14.16.0
V8: 8.9.255.24-electron.0
OS: Windows_NT x64 10.0.19042

Extensions Tab:
there are others installed but disabled
image

PIO Core and Extension version: Core 5.5.1 Home 3.3.4

platform.ini:

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
upload_speed = 921000
upload_port = COM7
monitor_port = COM7
build_flags =
-DCORE_DEBUG_LEVEL=4
-DCONFIG_ARDUHAL_LOG_COLORS=1
;monitor_flags = --raw
monitor_filters = direct, esp32_exception_decoder
lib_extra_dirs = …....\common\AwardLib

.vscode/c_cpp_properties.json

I had the same problem because i reinstalled the Window. But I fix it.

After installing the vs code and platformIO, I opened the project without making a new project from platformio. So it did not download the required files to run program. When I checked .platformio\packages\framework-arduinoespressif32\tools folder from drive c, there was only one file. Then, I reinstall platformio and made a new project, it downloaded the all required files, and the problem was fixed.

Try this method, described below.

I encountered the same problem - in my case it was caused by wrong settings of VSCode workspace.
This solved the problem for me:

  • Close VSCode workspace
  • Remove .vscode folder in the problematic project
  • Open new workspace, add folders containing all PIO projects
  • Save workspace, reload VSCode.

Alternatively, open file your_workspace_name.code-workspace and check whether your problematic project is included within "folders" tag. If not, add new entry and reload VSCode.

I too am now experiencing this issue after 18 months of great success with PIO!

It seem s to effect any project I now load.

Issues started a week or so ago following a pack of upgrades VSC, PIO, Espressif32, …
Maybe

pio upgrade --dev

I started getting PIO multiple Core errors on build so tried the proposed

pip uninstall platformio

But this left the same error so tried uninstalling from VSC and re-installing.
Now it seems that I have this Cannot open source file “Arduino.h”problem as VSC shows blue squiggle under

#include <Arduino.h>

Deleting .vscode has no effect and now building gives the following:

Resolving wemos_d1_mini32 dependencies…

Platform Manager: Installing espressif32 @ 3.0.0

Downloading 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%

Unpacking

Platform Manager: espressif32@3.0.0 has been installed!

Tool Manager: Installing tasmota/framework-arduinoespressif32 @ 3.10006.210420

Error: Could not find the package with ‘tasmota/framework-arduinoespressif32 @ 3.10006.210420’ requirements for your system ‘windows_amd64’

Seems like you’ve installed some older third-party platform for espressif32, the official GitHub - platformio/platform-espressif32: Espressif 32: development platform for PlatformIO would try to pull in the Tasmota version of the core.

Try clsing VSCode, deleting C:\Users\<user>\.platformio\ completely, reopening VSCode, letting PlatformIO reinitialize and then build the project again.

If it still fails, you might have a very outdated version of the project you’re trying to build (Tasmota?), referencing deleted packages, and you should try to get the newest version of it.