PlatformIO Community

Include error: e.g. Arduino.h, Wire.h

Hi,
I’m using PlatformIO(v. 1.10.0) and Visual Studio Code for Arduino Programming. I’ve only installed vsc, the platformio plugin and the microsoft c/cpp intellisense plugin (0.26.3 insiders 2).
Every include line is underlined red and I got “Source could not be found check path…” but at compile time everything is uploaded to the board and is working.
I’m using an Arduino Nano board.

I’ve already deleted .vscode folder many times and used the “Rebuild IntelliSense Index”.
I`ve although run the “C/C++ Reset IntellisenseDatabase” command in the terminal.

The main.cpp include part:


#include <Bounce2.h>
#include <EEPROM.h>
#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <TeaTimer.h>
#include <Arduino.h>



The platformio.ini:
[env:nanoatmega328new]
platform = atmelavr
board = nanoatmega328new
framework = arduino
monitor_speed = 115200
upload_port = /dev/cu.usbserial-141210
lib_deps = Bounce2, Servo


And the c/c++ settings.json:


"arduino.path": "/Applications/Arduino.app",
"arduino.additionalUrls": [
   "http://arduino.esp8266.com/stable/package_esp8266com_index.json"
],
"C_Cpp.updateChannel": "Insiders",
"C_Cpp.default.cppStandard": "c++20",
"C_Cpp.default.cStandard": "c11",
"C_Cpp.clang_format_sortIncludes": true,
"editor.formatOnType": true,
"[cpp]": {
    "editor.defaultFormatter": "ms-vscode.cpptools"
},
"C_Cpp.default.intelliSenseMode": "msvc-x64",
"platformio-ide.useDevelopmentPIOCore": true

}


The code compiles fine. There are only the include errors in the editor and therefore no code completion.

Can you revert to a stable version and report if the error is still there?

Also what’s the content of the .vscode\c_cpp_properties.json? (pastebin if too long)

1 Like

I changed to the stable Version 0.26.2 and the red lines changed to blue ones, but still the same include error. I use MacOS
The c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "!!! WARNING !!! AUTO-GENERATED FILE, PLEASE DO NOT MODIFY IT AND USE https://docs.platformio.org/page/projectconf/section_env_build.html#build-flags"
        },
        {
            "name": "Mac",
            "macFrameworkPath": [],
            "includePath": [
                "/Users/belial/Documents/Arduino/Projects/tea_maker_nano/TeaMakerNano/include",
                "/Users/belial/Documents/Arduino/Projects/tea_maker_nano/TeaMakerNano/src",
                "/Users/belial/Documents/Arduino/Projects/tea_maker_nano/TeaMakerNano/lib/LiquidCrystal_I2C",
                "/Users/belial/.platformio/packages/framework-arduino-avr/libraries/EEPROM/src",
                "/Users/belial/.platformio/packages/framework-arduino-avr/libraries/Wire/src",
                "/Users/belial/Documents/Arduino/Projects/tea_maker_nano/TeaMakerNano/.pio/libdeps/nanoatmega328new/Servo_ID883/src",
                "/Users/belial/Documents/Arduino/Projects/tea_maker_nano/TeaMakerNano/.pio/libdeps/nanoatmega328new/Bounce2_ID1106/src",
                "/Users/belial/.platformio/packages/framework-arduino-avr/cores/arduino",
                "/Users/belial/.platformio/packages/framework-arduino-avr/variants/eightanaloginputs",
                "/Users/belial/.platformio/packages/framework-arduino-avr/libraries/HID/src",
                "/Users/belial/.platformio/packages/framework-arduino-avr/libraries/SPI/src",
                "/Users/belial/.platformio/packages/framework-arduino-avr/libraries/SoftwareSerial/src",
                "/Users/belial/.platformio/packages/tool-unity",
                ""
            ],
            "browse": {
                "limitSymbolsToIncludedHeaders": true,
                "path": [
                    "/Users/belial/Documents/Arduino/Projects/tea_maker_nano/TeaMakerNano/include",
                    "/Users/belial/Documents/Arduino/Projects/tea_maker_nano/TeaMakerNano/src",
                    "/Users/belial/Documents/Arduino/Projects/tea_maker_nano/TeaMakerNano/lib/LiquidCrystal_I2C",
                    "/Users/belial/.platformio/packages/framework-arduino-avr/libraries/EEPROM/src",
                    "/Users/belial/.platformio/packages/framework-arduino-avr/libraries/Wire/src",
                    "/Users/belial/Documents/Arduino/Projects/tea_maker_nano/TeaMakerNano/.pio/libdeps/nanoatmega328new/Servo_ID883/src",
                    "/Users/belial/Documents/Arduino/Projects/tea_maker_nano/TeaMakerNano/.pio/libdeps/nanoatmega328new/Bounce2_ID1106/src",
                    "/Users/belial/.platformio/packages/framework-arduino-avr/cores/arduino",
                    "/Users/belial/.platformio/packages/framework-arduino-avr/variants/eightanaloginputs",
                    "/Users/belial/.platformio/packages/framework-arduino-avr/libraries/HID/src",
                    "/Users/belial/.platformio/packages/framework-arduino-avr/libraries/SPI/src",
                    "/Users/belial/.platformio/packages/framework-arduino-avr/libraries/SoftwareSerial/src",
                    "/Users/belial/.platformio/packages/tool-unity",
                    ""
                ]
            },
            "defines": [
                "PLATFORMIO=40100",
                "ARDUINO_AVR_NANO",
                "F_CPU=16000000L",
                "ARDUINO_ARCH_AVR",
                "ARDUINO=10808",
                "__AVR_ATmega328P__",
                ""
            ],
            "intelliSenseMode": "clang-x64",
            "cStandard": "c11",
            "cppStandard": "c++11",
            "compilerPath": "\"/Users/belial/.platformio/packages/toolchain-atmelavr/bin/avr-gcc\" -mmcu=atmega328p"
        }
    ],
    "version": 4
}

Hm I can’t even reproduce this with 0.26.3-insiders2 and VSCode 1.41.1 version and the shown extensions.

Can you screenshot the enable extensions quickly? The c_cpp_properties.json looks good and the Arduino core directory is also in there.

1 Like

Thanks for your help.
Here is a screenshot of the extensions.

Also with the 0.26.2 extensions no problem. What is the VSCode version and the Home and Core versions shown in te PIO Home screen? (left sidebar Alien icon -> PIO Home -> Open)

I’m using this VSCode version:

Version: 1.41.1
Commit: 26076a4de974ead31f97692a0d32f90d735645c0
Date: 2019-12-18T14:57:51.166Z
Electron: 6.1.5
Chrome: 76.0.3809.146
Node.js: 12.4.0
V8: 7.6.303.31-electron.0
OS: Darwin x64 19.2.0

and PIO Home 3.0.1 and Core 4.1.0

I just created a new PIO Arduino project, and the #include<Arduino.h> is found and IntelliSense code completion is working as expected. And also when adding the Bounce2 library the #include<Bounce.h> and everything else is working fine.
The error is in the other project.

I think I could reproduce the error.
I created a new project and everything is working fine. After I deleted the .vscode folder and restarted, the folder is automatically recreated but now I have the strange include errors. No IntelliSense reset or PIO rebuild index can fix the problem now.

Try opening a new window (File -> New Window), closing the other one, and then do File -> Open Folder and re-open your project. There could be something wrong with the workspace itself… sometimes this knocks some sense back into VSCode/IntelliSense.