Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Extension should automagically fill the c_cpp_properties.json, so intellisense works out of the box #438

Open
mundodisco8 opened this issue Nov 4, 2017 · 69 comments

Comments

@mundodisco8
Copy link

@mundodisco8 mundodisco8 commented Nov 4, 2017

EDIT: 07/03/2018: My understanding of the issue has improved since I opened it. I think that the extension should fill the intellisense config file on the fly based on the board being selected by the user.

To my knowledge, the Arduino IDE checks for libraries in 4 places: the main Arduino installation path (in windows c:\program files....), any board-specific version of the libraries for this board ("...\appdata\local..."), your sketchbook location and a "libraries" folder for that particular sketch. Ideally, you would install your libraries in your sketchbook location, so they are available for all your projects.

I've just installed VS Code and the Arduino plugin, and it seems to be able to know that my sketchbook location is not the default, as I can see the examples of the libraries that I've installed there, and I can compile my sketch. In any case, I get tens of intellisense errors, as intellisense seems incapable to follow the paths for the includes. I can add the sketchbook location libraries to the c_cpp_properties.json, and either add all the libraries used there (painfull) or add the base "libraries" folder and then tweak the includes to have partial paths (less painfull), but even in these cases, intellisense will complain that it can't find any of the libraries this files might use. And I would have to do it for all my projects, one by one.

What am I doing wrong? why doesn't this plugin pick the usual library locations? Is it normal to have 100s of intellisense errors? is that really the way it's meant to be?

Sorry, I'm new to Visual Studio and Visual Studio Code, and I'm quite sure that the problem it's me not being able to find out the logic behind them, but I can't find any info on the internet either.

I'm using windows 10 64 bits, and my arduino Ide is at the latest version. The relevant part of my c_cpp_settings.json of this project is:

            "name": "Win32",
            "includePath": [
                "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/include/*",
                "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/um",
                "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/ucrt",
                "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/shared",
                "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/winrt",
                "${workspaceRoot}",
                "C:\\Users\\Joel\\AppData\\Local\\Arduino15\\packages\\SODAQ\\hardware\\samd\\1.6.14\\cores\\arduino"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE"
            ],
            "intelliSenseMode": "msvc-x64",
            "browse": {
                "path": [
                    "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/include/*",
                    "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/um",
                    "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/ucrt",
                    "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/shared",
                    "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/winrt",
                    "${workspaceRoot}",
                    "C:\\Users\\Joel\\AppData\\Local\\Arduino15\\packages\\SODAQ\\hardware\\samd\\1.6.14\\cores\\arduino"
                ],
                "limitSymbolsToIncludedHeaders": false,
                "databaseFilename": ""
            }
        }

This is a screenshot of my project

2017-11-04_1307

@yaohaizh

This comment has been minimized.

Copy link
Contributor

@yaohaizh yaohaizh commented Nov 4, 2017

Please see here to see whether help resolve this issue?
https://github.com/Microsoft/vscode-arduino/wiki/FAQ

By default, the Arduino extension doesn't pick up all the head files. You can either pop up the command "Arduino: Library Manager" to include the header file to your paths.

@mundodisco8

This comment has been minimized.

Copy link
Author

@mundodisco8 mundodisco8 commented Nov 6, 2017

Hi,

I just open an example, the blink example, and used the arduino Uno as board. That way, my c_cpp_properties.json has just these two folders:

"C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino",
"${workspaceRoot}"

With that, all the Arduino-defined functions and variables are highlighted as undefined (pinMode, digitalWrite, HIGH,...).

It may be that I don't get how this thing is supposed to work, but I expect from the Arduino plugin to get all these methods by default. I also don't understand why doesn't it search for libraries where the Arduino IDE is expecting to find libraries (that is, the installation folder, the roaming/local/... folder where your boards are installed and the sketchbook location). These folders should be added by default. In any case, even if I add them, I can't get it to work. Yes, it compiles, but it's impossible to use this in a medium sized sketch without getting dozens of errors that make debugging a nightmare.

If my understanding is correct, only the folders in the includePath parameter are used for intellisense, but the search in them is not recursive. I don't know what folders do I have to add to get all the different definitions and methods and whatnot from Arduino working, but I suspect that it could be again dozens of them, not including all the folders I have to include to make a library work if it has dependencies... Is there a way to get Intellisense working on the Arduino plugin or am I doing something that is simply not achievable?

@bandrews

This comment has been minimized.

Copy link

@bandrews bandrews commented Nov 7, 2017

I've been fighting the same thing; since the intellisense parser changed to requiring exact paths from being willing to follow recursive directories, it's basically impossible to set up all the include paths necessary for Arduino usage.

I've been able to add all the libraries to the browse path, which inexplicably does work with recursion. Then, VS Code will suggest folders that are missing from the include path in the light bulb bubble. But I have to play whack-a-mole going deep into the bowels of included microcontroller library structures to get everything added. And the suggestions stop working after you pick only one, so you end up with lots of missing libraries and no way to discover the necessary paths for them...

This really needs to be fixed by the C/C++ extension authors, but judging from their issues database they've seemed stubbornly resistant to feedback requesting the return of recursive search paths. :(

@mundodisco8

This comment has been minimized.

Copy link
Author

@mundodisco8 mundodisco8 commented Nov 8, 2017

That's a shame, let's see how things develop, but it looks like a dealbreaker, at least for me at the moment. :(

@aldrDev

This comment has been minimized.

Copy link

@aldrDev aldrDev commented Nov 11, 2017

Also been fighting this issue. I have been trying to use the LiquidCrystal library for a project of mine, First it's annoying and unwieldy trying to point to that file - let alone dig around to then find (and point to) the dependencies within that. The c_cpp_properties.json file is becoming a mess trying to keep - I'm rather discouraged to work on a bigger project which might need more libraries.

Any other solutions or alternatives for now? It's a shame because I love Visual Studio Code and it would be perfect to add another type of project to it (I use it for Unity (C#), Java, and Web Development with zero issues)

@yaohaizh

This comment has been minimized.

Copy link
Contributor

@yaohaizh yaohaizh commented Nov 13, 2017

For please this value to your vscode setting file to see whether fix the intellisense issue:

"C_Cpp.intelliSenseEngine": "Tag Parser",
@aldrDev

This comment has been minimized.

Copy link

@aldrDev aldrDev commented Nov 14, 2017

This partially works (In that it stops the problems showing up in my test.ino file; and it seems I can show IntelliSense for methods not affected by problematic includes deeper down the rabbit hole)

As you can see

image

It will suffice for now - At least I can program for (and build) to my Arduino from the comfort of VS Code :) Looking forward to see even tighter / full integration soon.

Thanks @yaohaizh

@JulianGmp

This comment has been minimized.

Copy link

@JulianGmp JulianGmp commented Nov 17, 2017

I was in a similar situation trying to set up vscode for programming ESP chips (using Arduino).
I got intellisense to work, but I haven't done too much testing so this solution might not be final one.

But it does give me preview for parameters in the FastLED Library, which is installed under D:\Users\Julian\Documents\Arduino\libraries\FastLED.
2017-11-17 21_47_49-ws2812_manager ino - source - visual studio code

Stuff I did:

  • Force Intellisense to use the "Tag Parser" in the User Settings:
"C_Cpp.intelliSenseEngineFallback": "Disabled",
"C_Cpp.intelliSenseEngine": "Tag Parser",
  • Set up the c_cpp_properties.json
{
    "name": "Arduino",
    "includePath": [
        "${workspaceRoot}"
    ],
    "browse": {
        "path": [
            "D:/Program Files (x86)/Arduino/hardware",
            "D:/Program Files (x86)/Arduino/libraries",
            "D:/Users/Julian/Documents/Arduino/libraries/",
            "D:/Users/Julian/Documents/Arduino/hardware/",
            "${workspaceRoot}"
        ],
        "limitSymbolsToIncludedHeaders": true,
        "databaseFilename": ""
    },
    "intelliSenseMode": "msvc-x64"
}

that way, only the Tag Parses will be used as the engine and the config in the c_cpp_properties.json becomes a lot simples, since intellisense reads directories recursively now. That way I also got the engine to read libraries I installed manually, since they are placed in my homedirectory (D:/Users/Julian/Documents/Arduino/libraries/). Same goes for boards I installed, like the ESP8266, which has its package sit in "D:/Users/Julian/Documents/Arduino/hardware/".
Also, I used this as a source.

I'm gonna try to config the Arduino extension from Microsoft as well now, if I run into some issues I can fix I will comment them here.

@dafzor

This comment has been minimized.

Copy link

@dafzor dafzor commented Nov 21, 2017

I have not tried the tag parser setting suggested here, but had come up with a solution which was to simply add all the include paths by hand.

For a basic hello world program on a UNO like this:

#include <Arduino.h>
#define LED_PIN 10

void setup() {
    pinMode(LED_PIN, OUTPUT);
}

void loop() {
    digitalWrite(LED_PIN, HIGH);
    delay(1000);
    digitalWrite(LED_PIN, LOW);
    delay(1000);
}

I need a C_Cpp_properties.json like this:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceRoot}",
                "C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino",
                "C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr\\avr\\include",
                "C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr\\lib\\gcc\\avr\\4.9.2\\include",
                "C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\mega"
            ],
            "browse": {
                "limitSymbolsToIncludedHeaders": false,
                "path": [
                    "${workspaceRoot}",
                    "C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino",
                    "C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr\\avr\\include",
                    "C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr\\lib\\gcc\\avr\\4.9.2\\include",
                    "C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\mega"
                ]
            },
            "intelliSenseMode": "msvc-x64"
        }
    ],
    "version": 3
}

Maybe changing it so that Arduino: Board Config actually includes all the needed paths could be a start for trying to fix the issue.

@InRiPa

This comment has been minimized.

Copy link

@InRiPa InRiPa commented Nov 22, 2017

@dafzor Thanks. I adjusted it for linux and it works. At least I got autocompletion and intellisense working. In case someone else needs it, here is my config:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "/usr/lib/gcc/avr/7.2.0/include",
                "/home/<user>/.arduino15/packages/arduino/hardware/avr/1.6.20/cores/arduino",
                "/usr/avr/include/",
                "/home/<user>/.arduino15/packages/arduino/tools/avr-gcc/4.9.2-atmel3.5.4-arduino2/avr/include",
                "/usr/share/arduino/hardware/archlinux-arduino/avr/variants/mega"
            ],
            "browse": {
                "limitSymbolsToIncludedHeaders": false,
                "path": [
                    "/usr/lib/gcc/avr/7.2.0/include",
                    "/home/<user>/.arduino15/packages/arduino/hardware/avr/1.6.20/cores/arduino",
                    "/usr/avr/include/",
                    "/home/<user>/.arduino15/packages/arduino/tools/avr-gcc/4.9.2-atmel3.5.4-arduino2/avr/include",
                    "/usr/share/arduino/hardware/archlinux-arduino/avr/variants/mega"
                ]
            },
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 3
}
@heyAyushh

This comment has been minimized.

Copy link

@heyAyushh heyAyushh commented Nov 28, 2017

Somebody Please tell this for mac too

@carlhung

This comment has been minimized.

Copy link

@carlhung carlhung commented Dec 16, 2017

I can't find the path for Mac

@stormbytes

This comment has been minimized.

Copy link

@stormbytes stormbytes commented Dec 17, 2017

Same issue.

On Mac:
Added '#include <Arduino.h>' to the top of my sketch which makes the errors go away.

Not sure about intellisense or anything else. Anyone working on this?

@JulianGmp

This comment has been minimized.

Copy link

@JulianGmp JulianGmp commented Dec 17, 2017

@stormbytes I think that is caused because the Arduino.h file isn't included by default in Visual Studio's mind. The Arduino Software obviously includes their core when compiling.
Adding the #include <Arduino.h> or the #include <Esp.h> when using ESP Controllers won't cause issues though. It's a bit annoying but oh well, better than having to use the Arduino "IDE"

@stormbytes

This comment has been minimized.

Copy link

@stormbytes stormbytes commented Dec 17, 2017

@JulianGmp what you're saying makes sense though Platformio team should have considered this when developing the VS extension. Having to add the header to each sketch is completely redundant and means that everyone who uses this extension is bound to run into this exact problem. It will do for now. I hope they fix this is the next update.

@JulianGmp

This comment has been minimized.

Copy link

@JulianGmp JulianGmp commented Dec 17, 2017

@stormbytes I'm not using PlatformIO, I'm using the Arduino Extension from Microsoft

But I guess both extensions didn't prevent this from happening, oh well not the End of the world

@yaohaizh

This comment has been minimized.

Copy link
Contributor

@yaohaizh yaohaizh commented Dec 18, 2017

The official Arduino IDE will include the <Arduino.h> behind in their tooling. But for VSCode Arduino extension, we have to include explicitly, just as normal C/C++ file to make the intellisense work. But you doesn't need this header file for build/upload.

@dafzor

This comment has been minimized.

Copy link

@dafzor dafzor commented Dec 18, 2017

Just leaving the info here that even if you setup the include paths the intellisense will still not work 100%. For example, if you include SD.h library and a line like this File myfile = SD.open("myfile"); it will show several type definition errors even though the sketch will compile and run correctly.

So I ended up moving to http://www.visualmicro.com until the vscode extension gets fixed.

@DavidKarlas

This comment has been minimized.

Copy link
Member

@DavidKarlas DavidKarlas commented Jan 6, 2018

On macOS, I added #include <Arduino.h> to beginning of .ino file and I filled c_cpp_properties.json content with:

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceRoot}",
                "/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino",
                "/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/variants/mega",
                "/Applications/Arduino.app/Contents/Java/hardware/tools/avr/avr/include",
                "/Applications/Arduino.app/Contents/Java/hardware/tools/avr/lib/gcc/avr/4.9.2/include"
            ],
            "defines": ["UBRRH"],
            "browse": {
                "limitSymbolsToIncludedHeaders": false,
                "path": [
                    "${workspaceRoot}",
                    "/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino",
                    "/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/variants/mega",
                    "/Applications/Arduino.app/Contents/Java/hardware/tools/avr/avr/include",
                    "/Applications/Arduino.app/Contents/Java/hardware/tools/avr/lib/gcc/avr/4.9.2/include"
                ]
            },
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 3
}

Notice that #include <Arduino.h> line shows error, but you can ignore it and have Intelisense working for rest of file...

@heroboy

This comment has been minimized.

Copy link

@heroboy heroboy commented Jan 10, 2018

I think you can run arduino_debug.exe, compile a sketch. You can look the console window for it how to call avr-g++ to know the predefined macros and include path. Finally my json file look like this:

{
    "configurations": [
        {
            "name": "Win32",
            "defines": [
                "F_CPU=16000000L",
                "ARDUINO=10805",
                "ARDUINO_AVR_UNO",
                "ARDUINO_ARCH_AVR"
            ],
            "includePath": [
                "D:\\tools\\arduino-1.8.5\\hardware\\arduino\\avr\\cores\\arduino",
                "D:\\tools\\arduino-1.8.5\\hardware\\arduino\\avr\\variants\\standard",
                "D:\\tools\\arduino-1.8.5\\hardware\\tools\\avr\\avr\\include",
                "D:\\tools\\arduino-1.8.5\\hardware\\tools\\avr\\lib\\gcc\\avr\\4.9.2\\include"
            ],
            "browse": {
                "limitSymbolsToIncludedHeaders": false,
                "path": [
                    "D:\\tools\\arduino-1.8.5\\hardware\\arduino\\avr\\cores\\arduino",
                    "D:\\tools\\arduino-1.8.5\\hardware\\arduino\\avr\\variants\\standard",
                    "D:\\tools\\arduino-1.8.5\\hardware\\tools\\avr\\avr\\include",
                    "D:\\tools\\arduino-1.8.5\\hardware\\tools\\avr\\lib\\gcc\\avr\\4.9.2\\include"
                ]
            },
            "intelliSenseMode": "msvc-x64"
        }
    ],
    "version": 3
}
@raffaeler

This comment has been minimized.

Copy link

@raffaeler raffaeler commented Jan 13, 2018

I also retried today to configure the support for intellisense and it doesn't work.
After configuring the includePath, now it request WProgram.h even if the Arduino installation is totally updated.
I don't want to waste time and give up.

@clouds56

This comment has been minimized.

Copy link

@clouds56 clouds56 commented Jan 20, 2018

If you meet something like identifier "Serial" not defined, also add "USBCON" into defines in configurations
See cpptools document for more details.

I'm not sure if there're other flags like this, while I hope the extension could do this automatically for us, since we have done setup the "Arduino Board Configuration".

@raffaeler

This comment has been minimized.

Copy link

@raffaeler raffaeler commented Jan 20, 2018

Nope, in my case the problem is the editor. No way to configure properly the intellisense and get rid of the squiggles on the includes

@clouds56

This comment has been minimized.

Copy link

@clouds56 clouds56 commented Jan 20, 2018

Which header is trying to request "WProgram.h"? In my linux package, there's no WProgram.h and no header's including it.

@dafzor

This comment has been minimized.

Copy link

@dafzor dafzor commented Jan 20, 2018

@raffaeler

This comment has been minimized.

Copy link

@raffaeler raffaeler commented Jan 20, 2018

The library is DHT.h from Adafruit and is updated.
The DHT.h file specifies the same preprocessor definitgions you wrote, but it complains
image

If I right click the DHT.h and navigate to definition, the DHT.h file gets opened.
Arduino IDE version 1.8.2
DHT unified 1.0.0
DHT sensor library 1.3.0

@clouds56

This comment has been minimized.

Copy link

@clouds56 clouds56 commented Jan 20, 2018

It's also about defines, the ARDUINO macro is not defined, add

defines: [ "ARDUINO=100" ],

to your c_cpp_properties.json

I'm assuming you're using this DHT.h, and your ARDUINO version is 100, change it if necessary.

@raffaeler

This comment has been minimized.

Copy link

@raffaeler raffaeler commented Jan 20, 2018

Looks far better now, thanks!
I am adding other include paths and then will try connecting the devices.

I don't understand why the vscode extension does not provide somthing to get this easier. Also the doc does is not clear about the settings needed to make it work.

@Pharap

This comment has been minimized.

Copy link

@Pharap Pharap commented Jul 4, 2018

I believe it's worth mentioning that if ${config:arduino.path} was allowed to be used in local user workspace files, that this:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceRoot}",
                "${config:arduino.path}/hardware/tools/avr/avr/include",
		"${config:arduino.path}/hardware/arduino/avr/cores/arduino",
		"${config:arduino.path}/hardware/arduino/avr/libraries/EEPROM/src",
		"${config:arduino.path}/hardware/tools/avr/lib/gcc/avr/4.9.2/include",
		"${config:arduino.path}/hardware/tools/avr/lib/gcc/avr/4.9.2/include-fixed"
            ],
            "browse": {
                "limitSymbolsToIncludedHeaders": false,
                "path": [
                    "${workspaceRoot}"
                ]
            },
            "intelliSenseMode": "msvc-x64",
            "cppStandard": "c++11"
        }
    ],
    "version": 3
}

Would be a suitable solution for the base case (without factoring the board in).
Likewise the boards could be found in "${config:arduino.path}/hardware/arduino/avr/variants/<board category>" (which is only actually needed for pins_arduino.h).

Perhaps the same effect could be achieved programmatically?

(As for 3rd party libraries added by the Arduino IDE, I think adding those libraries probably counts as a separate issue maybe?)

@sslupsky

This comment has been minimized.

Copy link

@sslupsky sslupsky commented Sep 21, 2018

Hi @Sneezry There is a file named "includes.cache" that the Arduino build process creates in the build directory. That file contains all the include paths for the project. Could you use this file to fill the intellisense include paths automagically?

@ljubomirb

This comment has been minimized.

Copy link

@ljubomirb ljubomirb commented Oct 15, 2018

Installation did not work for me out of the box. I tried for several hours all sorts of combinations, and apparently, defines may be the key, but I'm simply not sure what did I miss.


            "defines": [
                "ARDUINO_AVR_NANO",
                "F_CPU=16000000L",
                "ARDUINO_ARCH_AVR",
                "ARDUINO=10805",
                "__AVR_ATmega328P__"
            ],
@sslupsky

This comment has been minimized.

Copy link

@sslupsky sslupsky commented Oct 24, 2018

@ljubomirb Here is what I use for the MKRWAN1300:

        "defines": [
            "ARDUINO=100",
            "ARDUINO_ARCH_SAMD",
            "ARDUINO_SAMD_MKRWAN1300",
            "__SAMD21G18A__",
            "BOARD_ID_arduino_mkrwan1300",
            "_VARIANT_ARDUINO_MKRWAN1300_"
        ],

It would be really cool if there was a way for the vscode plugin to automatically pick the defines from the make file.

@ljubomirb

This comment has been minimized.

Copy link

@ljubomirb ljubomirb commented Oct 24, 2018

@sslupsky
I'm not even sure what is or what was wrong. Most of my problems went away when I set tag parser as IntelliSense engine. So, something is missing either in "how to" instructions, or settings, or is otherwise making us doing the wrong steps. If "tag parser" should be used, then it should be set on automatically. For me, visual studio 201x community still works better with arduino plugin at the moment, but vscode, once fixed, definitely has a great future!

@mundodisco8

This comment has been minimized.

Copy link
Author

@mundodisco8 mundodisco8 commented Oct 24, 2018

@danindiana

This comment has been minimized.

Copy link

@danindiana danindiana commented Nov 8, 2018

Note to Linux VScode users: Make sure to use "Arduino: upload" as opposed to "upload using programmer." The latter will not upload to the arduino board but instead throw an "Exit with code=1" leaving you no details.

Easy mistake to make since "upload using programmer" can appear as the first and only suggestion in the drop down menu unless you manually type Arduino: upload.

OS: Ubuntu 16.04 xenial
Kernel: x86_64 Linux 4.15.0-38-generic
Uptime: 18m
Packages: 3512
Shell: bash 4.3.48
Resolution: 2560x1080
DE: Unity 7.4.5
WM: Compiz
WM Theme: Radiance
Radiance [GTK2]
, Radiance [GTK3]
Icon Theme: ubuntu-mono-light
Font: Ubuntu 11
CPU: AMD Ryzen 5 1600X Six-Core @ 4GHz
GPU: GeForce GTX 1050
RAM: 2695MiB / 16034MiB

@aroman

This comment has been minimized.

Copy link

@aroman aroman commented Nov 14, 2018

If anyone else has been struggling to get proper Intellisense support in VS Code for Arduino, without randomly hunting pasting in defines and manually resolving pathing issues, I'd strongly recommend the PlatformIO IDE VS Code extension. Don't be scared/confused by the website about paid plans (I was), the only thing you need is a standalone VS Code extension — free and open-source (MIT).

After struggling to get proper code completion working with this plugin for a few hours, I installed that plugin and 5 minutes later everything worked perfectly. No config editing. It already does everything this bug (now a year old!) is seeking — it just sets everything up automagically. Even after hours of tweaking this plugin, I still was only able to get partial code completion by falling back to the tag-based engine, which severely limits the quality of code completion.

I have no affiliation with PlatformIO at all. I wanted to love vscode-arduino, since it seemed lighter weight and I only care about Arduino — it's even officially recommended by Microsoft. But now I can definitely say that PlatformIO seems to be the way to go.

@Wiqkszon

This comment has been minimized.

Copy link

@Wiqkszon Wiqkszon commented Nov 26, 2018

code_2018-11-25_20-47-51
code_2018-11-25_20-49-36

Hi, I'm new on this program the problem I have is when I try to open an example (Blink) I got this 2 errors. I already try adding new paths on c_pp_properties.json, but it doesn't work.
When I upload the code it just work fine but how do I get rid of those errors?

@MarianMajik

This comment has been minimized.

Copy link

@MarianMajik MarianMajik commented Jan 1, 2019

I've had problem with VS Code on OSX marking missing identifiers for NodeMCU.

In my case helped to force path for Arduino libraries:

        "includePath": [
            "/Users/mm/Library/Arduino15/packages/esp8266/tools/**",
            "/Users/mm/Library/Arduino15/packages/esp8266/hardware/esp8266/2.3.0/**"
        ],
        "forcedInclude": [  
             "/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h"
        ],
       "macFrameworkPath": [
            "/System/Library/Frameworks",
            "/Library/Frameworks"
        ],
@clankill3r

This comment has been minimized.

Copy link

@clankill3r clankill3r commented Jan 14, 2019

Yet another huge disappointment by Microsoft.
Hope this will get some love in the future.

Anyway, for OSX this is what I use at the moment for arduino 1.8.7. Be aware that I have a folder applications2 and that I renamed the arduino app to the version.

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**",
                "/Applications2/Arduino-1.8.7.app/Contents/Java/hardware/arduino/avr/cores/arduino",
                "/Applications2/Arduino-1.8.7.app/Contents/Java/hardware/arduino/avr/variants/standard",
                "/Applications2/Arduino-1.8.7.app/Contents/Java/hardware/tools/avr/include",
                "/Applications2/Arduino-1.8.7.app/Contents/Java/hardware/tools/avr/avr/include",
                "/Applications2/Arduino-1.8.7.app/Contents/Java/hardware/tools/avr/avr/include/avr",
                "/Applications2/Arduino-1.8.7.app/Contents/Java/hardware/tools/avr/lib/gcc/avr/5.4.0/include"
            ],
            "defines": [
                "ARDUINO=100",
                "_DEBUG",
                "UNICODE",
                "__AVR_ATmega328P__",
                "__AVR_ENHANCED__"
            ],
            "macFrameworkPath": [
                "/System/Library/Frameworks",
                "/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}
@sudoerChris

This comment has been minimized.

Copy link

@sudoerChris sudoerChris commented Jan 22, 2019

In my experience, "compilerPath" might set to Visual Studio one, which cause a lots of false error, including the "missing includepath" warning mentioned above
change it to "compilerPath": "<Your Arduino IDE installation path>\\hardware\\tools\\avr\\bin\\avr-gcc.exe" solve the problem, no need to manually change includepath or add "browse" definition

@TheTrigger

This comment has been minimized.

Copy link

@TheTrigger TheTrigger commented Feb 21, 2019

this worked for me on Windows 10

"includePath": [
	"${workspaceFolder}/**",
	"C:/Program Files (x86)/Arduino/hardware/**",
	"C:/Program Files (x86)/Arduino/libraries/**",
	"C:/Users/Fabio/Documents/Arduino/libraries/**",
	"C:/Users/Fabio/Documents/Arduino/hardware/**"
],
@elemenofi

This comment has been minimized.

Copy link

@elemenofi elemenofi commented Mar 1, 2019

i had downloaded the Arduino IDE from arduino.cc using the Windows 10 "Get" feature... never again! i could never find my arduino directory and I almost go nuts. I get so stressed... Anyway I went back to arduino.cc and this time i downloaded a normal windows installer, put /Arduino in program files and then the snippets in this post made it work! hope that helps the next poor bastard!

@oddstr13

This comment has been minimized.

Copy link

@oddstr13 oddstr13 commented Mar 7, 2019

In my experience, "compilerPath" might set to Visual Studio one, which cause a lots of false error, including the "missing includepath" warning mentioned above
change it to "compilerPath": "<Your Arduino IDE installation path>\\hardware\\tools\\avr\\bin\\avr-gcc.exe" solve the problem, no need to manually change includepath or add "browse" definition

This fixed the issue I was having with flash string macro (F("Gimme more memory please")) messing up the error reporting.

I also set "intelliSenseMode": "gcc-x64", mostly just to match the compiler.

@smamusa

This comment has been minimized.

Copy link

@smamusa smamusa commented Apr 20, 2019

For please this value to your vscode setting file to see whether fix the intellisense issue:

"C_Cpp.intelliSenseEngine": "Tag Parser",

This is by far the simplest solution, I added this in my
File -> Preferences -> Settings -> Extensions -> Arduino -> settings.json file
And it fixed the problems popping up.
NOTE: I'm using it only for navigating code, I'm still uploading through Arduino IDE.

@hywhuangyuwei

This comment has been minimized.

Copy link

@hywhuangyuwei hywhuangyuwei commented May 10, 2019

If you meet something like identifier "Serial" not defined, also add "USBCON" into defines in configurations
See cpptools document for more details.

I'm not sure if there're other flags like this, while I hope the extension could do this automatically for us, since we have done setup the "Arduino Board Configuration".

Thanks! It helps!

@ATiltedTree

This comment has been minimized.

Copy link

@ATiltedTree ATiltedTree commented May 12, 2019

For anyone having problems getting this to work on archlinux, install the AUR package arduino-git and use this file.

{
  "configurations": [
    {
      "name": "Linux",
      "includePath": [
        "/usr/share/arduino/tools/**",
        "/usr/share/arduino/hardware/arduino/avr/**",
        "/usr/share/arduino/hardware/tools/**",
        "/usr/share/arduino/libraries/**"
      ],
      "browse": {
        "path": [
          "/usr/share/arduino/tools",
          "/usr/share/arduino/hardware/arduino/avr",
          "/usr/share/arduino/hardware/tools",
          "/usr/share/arduino/libraries"
        ]
      },
      "forcedInclude": [
        "/usr/share/arduino/hardware/arduino/avr/cores/arduino/Arduino.h"
      ],
      "intelliSenseMode": "gcc-x64",
      "compilerPath": "/usr/bin/gcc",
      "cStandard": "c11",
      "cppStandard": "c++17",
      "defines": [
          "USBCON"
     ]
    }
  ],
  "version": 4
}

You have to install the AUR package because the package arduino and arduino-avr-core are using a different file structure

@bfxdev

This comment has been minimized.

Copy link

@bfxdev bfxdev commented Jul 2, 2019

I wrote a complete tutorial on how to setup VSCode for Arduino (especially for a game console named "Gamebuino", but largely applicable to other boards)

The c_cpp_properties.json file is built by taking parts of the sketch compilation command. It gives a perfect result with the default IntelliSense engine and provides a version for different Arduino IDE flavors (Win, Linux, macOS).

Now what annoys me: the vscode extension now adds paths, and there is no way to prevent it.

{
    "env": {
        "WIN32_PACKAGES_PATH": "${env:USERPROFILE}/AppData/Local/Arduino15/packages",
        "WIN32_SKETCHBOOK_PATH": "${env:USERPROFILE}/Documents/Arduino",
        "WIN32_APP_PACKAGES_PATH": "${env:USERPROFILE}/Documents/ArduinoData/packages",
        "MAC_PACKAGES_PATH": "${env:HOME}/Library/Arduino15/packages",
        "MAC_SKETCHBOOK_PATH": "${env:HOME}/Arduino",
        "LINUX_PACKAGES_PATH": "${env:HOME}/.arduino15/packages",
        "LINUX_SKETCHBOOK_PATH": "${env:HOME}/Arduino",
        "PORTABLE_PACKAGES_PATH": "${config:arduino.path}/portable/packages",
        "PORTABLE_SKETCHBOOK_PATH": "${config:arduino.path}/portable/sketchbook"
    },
    "configurations": [
        {
            "name": "Win32",
            "intelliSenseMode": "gcc-x64",
            "cStandard": "c11",
            "cppStandard": "c++11",
            "compilerPath": "\"${env:WIN32_PACKAGES_PATH}/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++.exe\" -mcpu=cortex-m0plus -std=gnu++11 -D__SKETCH_NAME__ -DF_CPU=48000000L -DARDUINO=10809 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD -D__SAMD21G18A__ -DUSB_VID=0x2341 -DUSB_PID=0x804d -DUSBCON -DUSB_MANUFACTURER -DUSB_PRODUCT",
            "includePath": [
                "${workspaceFolder}",
                "${env:WIN32_PACKAGES_PATH}/arduino/tools/CMSIS/4.5.0/CMSIS/Include",
                "${env:WIN32_PACKAGES_PATH}/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL",
                "${env:WIN32_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/cores/arduino",
                "${env:WIN32_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/variants/gamebuino_meta",
                "${env:WIN32_SKETCHBOOK_PATH}/libraries/Gamebuino_META/src",
                "${env:WIN32_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/libraries/SPI"
            ],
            "browse": {
                "path": [
                    "${workspaceFolder}",
                    "${env:WIN32_PACKAGES_PATH}/arduino/tools/CMSIS/4.5.0/CMSIS/Include",
                    "${env:WIN32_PACKAGES_PATH}/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL",
                    "${env:WIN32_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/cores/arduino",
                    "${env:WIN32_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/variants/gamebuino_meta",
                    "${env:WIN32_SKETCHBOOK_PATH}/libraries/Gamebuino_META/src",
                    "${env:WIN32_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/libraries/SPI"
                ],
                "limitSymbolsToIncludedHeaders": true
            },
            "forcedInclude": [
                "${env:WIN32_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/cores/arduino/Arduino.h",
                "${env:WIN32_SKETCHBOOK_PATH}/libraries/Gamebuino_META/src/Gamebuino-Meta.h"
            ]
        },
        {
            "name": "Win32-Portable",
            "intelliSenseMode": "gcc-x64",
            "cStandard": "c11",
            "cppStandard": "c++11",
            "compilerPath": "\"${env:PORTABLE_PACKAGES_PATH}/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++.exe\" -mcpu=cortex-m0plus -std=gnu++11 -D__SKETCH_NAME__ -DF_CPU=48000000L -DARDUINO=10809 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD -D__SAMD21G18A__ -DUSB_VID=0x2341 -DUSB_PID=0x804d -DUSBCON -DUSB_MANUFACTURER -DUSB_PRODUCT",
            "includePath": [
                "${workspaceFolder}",
                "${env:PORTABLE_PACKAGES_PATH}/arduino/tools/CMSIS/4.5.0/CMSIS/Include",
                "${env:PORTABLE_PACKAGES_PATH}/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL",
                "${env:PORTABLE_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/cores/arduino",
                "${env:PORTABLE_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/variants/gamebuino_meta",
                "${env:PORTABLE_SKETCHBOOK_PATH}/libraries/Gamebuino_META/src",
                "${env:PORTABLE_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/libraries/SPI"
            ],
            "browse": {
                "path": [
                    "${workspaceFolder}",
                    "${env:PORTABLE_PACKAGES_PATH}/arduino/tools/CMSIS/4.5.0/CMSIS/Include",
                    "${env:PORTABLE_PACKAGES_PATH}/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL",
                    "${env:PORTABLE_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/cores/arduino",
                    "${env:PORTABLE_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/variants/gamebuino_meta",
                    "${env:PORTABLE_SKETCHBOOK_PATH}/libraries/Gamebuino_META/src",
                    "${env:PORTABLE_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/libraries/SPI"
                ],
                "limitSymbolsToIncludedHeaders": true
            },
            "forcedInclude": [
                "${env:PORTABLE_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/cores/arduino/Arduino.h",
                "${env:PORTABLE_SKETCHBOOK_PATH}/libraries/Gamebuino_META/src/Gamebuino-Meta.h"
            ]
        },
        {
            "name": "Win32-App",
            "intelliSenseMode": "gcc-x64",
            "cStandard": "c11",
            "cppStandard": "c++11",
            "compilerPath": "\"${env:WIN32_APP_PACKAGES_PATH}/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++.exe\" -mcpu=cortex-m0plus -std=gnu++11 -D__SKETCH_NAME__ -DF_CPU=48000000L -DARDUINO=10809 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD -D__SAMD21G18A__ -DUSB_VID=0x2341 -DUSB_PID=0x804d -DUSBCON -DUSB_MANUFACTURER -DUSB_PRODUCT",
            "includePath": [
                "${workspaceFolder}",
                "${env:WIN32_APP_PACKAGES_PATH}/arduino/tools/CMSIS/4.5.0/CMSIS/Include",
                "${env:WIN32_APP_PACKAGES_PATH}/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL",
                "${env:WIN32_APP_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/cores/arduino",
                "${env:WIN32_APP_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/variants/gamebuino_meta",
                "${env:WIN32_SKETCHBOOK_PATH}/libraries/Gamebuino_META/src",
                "${env:WIN32_SKETCHBOOK_PATH}/libraries/FixedPoints/src",
                "${env:WIN32_APP_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/libraries/SPI"
            ],
            "browse": {
                "path": [
                    "${workspaceFolder}",
                    "${env:WIN32_APP_PACKAGES_PATH}/arduino/tools/CMSIS/4.5.0/CMSIS/Include",
                    "${env:WIN32_APP_PACKAGES_PATH}/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL",
                    "${env:WIN32_APP_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/cores/arduino",
                    "${env:WIN32_APP_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/variants/gamebuino_meta",
                    "${env:WIN32_SKETCHBOOK_PATH}/libraries/Gamebuino_META/src",
                    "${env:WIN32_APP_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/libraries/SPI"
                ],
                "limitSymbolsToIncludedHeaders": true
            },
            "forcedInclude": [
                "${env:WIN32_APP_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/cores/arduino/Arduino.h",
                "${env:WIN32_SKETCHBOOK_PATH}/libraries/Gamebuino_META/src/Gamebuino-Meta.h"
            ]
        },
        {
            "name": "Mac",
            "intelliSenseMode": "gcc-x64",
            "cStandard": "c11",
            "cppStandard": "c++11",
            "compilerPath": "\"${env:MAC_PACKAGES_PATH}/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++.exe\" -mcpu=cortex-m0plus -std=gnu++11 -D__SKETCH_NAME__ -DF_CPU=48000000L -DARDUINO=10809 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD -D__SAMD21G18A__ -DUSB_VID=0x2341 -DUSB_PID=0x804d -DUSBCON -DUSB_MANUFACTURER -DUSB_PRODUCT",
            "includePath": [
                "${workspaceFolder}",
                "${env:MAC_PACKAGES_PATH}/arduino/tools/CMSIS/4.5.0/CMSIS/Include",
                "${env:MAC_PACKAGES_PATH}/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL",
                "${env:MAC_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/cores/arduino",
                "${env:MAC_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/variants/gamebuino_meta",
                "${env:MAC_SKETCHBOOK_PATH}/libraries/Gamebuino_META/src",
                "${env:MAC_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/libraries/SPI"
            ],
            "browse": {
                "path": [
                    "${workspaceFolder}",
                    "${env:MAC_PACKAGES_PATH}/arduino/tools/CMSIS/4.5.0/CMSIS/Include",
                    "${env:MAC_PACKAGES_PATH}/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL",
                    "${env:MAC_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/cores/arduino",
                    "${env:MAC_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/variants/gamebuino_meta",
                    "${env:MAC_SKETCHBOOK_PATH}/libraries/Gamebuino_META/src",
                    "${env:MAC_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/libraries/SPI"
                ],
                "limitSymbolsToIncludedHeaders": true
            },
            "forcedInclude": [
                "${env:MAC_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/cores/arduino/Arduino.h",
                "${env:MAC_SKETCHBOOK_PATH}/libraries/Gamebuino_META/src/Gamebuino-Meta.h"
            ]
        },
        {
            "name": "Mac-Portable",
            "intelliSenseMode": "gcc-x64",
            "cStandard": "c11",
            "cppStandard": "c++11",
            "compilerPath": "\"${env:PORTABLE_PACKAGES_PATH}/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++.exe\" -mcpu=cortex-m0plus -std=gnu++11 -D__SKETCH_NAME__ -DF_CPU=48000000L -DARDUINO=10809 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD -D__SAMD21G18A__ -DUSB_VID=0x2341 -DUSB_PID=0x804d -DUSBCON -DUSB_MANUFACTURER -DUSB_PRODUCT",
            "includePath": [
                "${workspaceFolder}",
                "${env:PORTABLE_PACKAGES_PATH}/arduino/tools/CMSIS/4.5.0/CMSIS/Include",
                "${env:PORTABLE_PACKAGES_PATH}/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL",
                "${env:PORTABLE_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/cores/arduino",
                "${env:PORTABLE_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/variants/gamebuino_meta",
                "${env:PORTABLE_SKETCHBOOK_PATH}/libraries/Gamebuino_META/src",
                "${env:PORTABLE_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/libraries/SPI"
            ],
            "browse": {
                "path": [
                    "${workspaceFolder}",
                    "${env:PORTABLE_PACKAGES_PATH}/arduino/tools/CMSIS/4.5.0/CMSIS/Include",
                    "${env:PORTABLE_PACKAGES_PATH}/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL",
                    "${env:PORTABLE_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/cores/arduino",
                    "${env:PORTABLE_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/variants/gamebuino_meta",
                    "${env:PORTABLE_SKETCHBOOK_PATH}/libraries/Gamebuino_META/src",
                    "${env:PORTABLE_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/libraries/SPI"
                ],
                "limitSymbolsToIncludedHeaders": true
            },
            "forcedInclude": [
                "${env:PORTABLE_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/cores/arduino/Arduino.h",
                "${env:PORTABLE_SKETCHBOOK_PATH}/libraries/Gamebuino_META/src/Gamebuino-Meta.h"
            ]
        },
        {
            "name": "Linux",
            "intelliSenseMode": "gcc-x64",
            "cStandard": "c11",
            "cppStandard": "c++11",
            "compilerPath": "\"${env:LINUX_PACKAGES_PATH}/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++.exe\" -mcpu=cortex-m0plus -std=gnu++11 -D__SKETCH_NAME__ -DF_CPU=48000000L -DARDUINO=10809 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD -D__SAMD21G18A__ -DUSB_VID=0x2341 -DUSB_PID=0x804d -DUSBCON -DUSB_MANUFACTURER -DUSB_PRODUCT",
            "includePath": [
                "${workspaceFolder}",
                "${env:LINUX_PACKAGES_PATH}/arduino/tools/CMSIS/4.5.0/CMSIS/Include",
                "${env:LINUX_PACKAGES_PATH}/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL",
                "${env:LINUX_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/cores/arduino",
                "${env:LINUX_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/variants/gamebuino_meta",
                "${env:LINUX_SKETCHBOOK_PATH}/libraries/Gamebuino_META/src",
                "${env:LINUX_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/libraries/SPI"
            ],
            "browse": {
                "path": [
                    "${workspaceFolder}",
                    "${env:LINUX_PACKAGES_PATH}/arduino/tools/CMSIS/4.5.0/CMSIS/Include",
                    "${env:LINUX_PACKAGES_PATH}/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL",
                    "${env:LINUX_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/cores/arduino",
                    "${env:LINUX_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/variants/gamebuino_meta",
                    "${env:LINUX_SKETCHBOOK_PATH}/libraries/Gamebuino_META/src",
                    "${env:LINUX_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/libraries/SPI"
                ],
                "limitSymbolsToIncludedHeaders": true
            },
            "forcedInclude": [
                "${env:LINUX_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/cores/arduino/Arduino.h",
                "${env:LINUX_SKETCHBOOK_PATH}/libraries/Gamebuino_META/src/Gamebuino-Meta.h"
            ]
        },
        {
            "name": "Linux-Portable",
            "intelliSenseMode": "gcc-x64",
            "cStandard": "c11",
            "cppStandard": "c++11",
            "compilerPath": "\"${env:PORTABLE_PACKAGES_PATH}/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++.exe\" -mcpu=cortex-m0plus -std=gnu++11 -D__SKETCH_NAME__ -DF_CPU=48000000L -DARDUINO=10809 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD -D__SAMD21G18A__ -DUSB_VID=0x2341 -DUSB_PID=0x804d -DUSBCON -DUSB_MANUFACTURER -DUSB_PRODUCT",
            "includePath": [
                "${workspaceFolder}",
                "${env:PORTABLE_PACKAGES_PATH}/arduino/tools/CMSIS/4.5.0/CMSIS/Include",
                "${env:PORTABLE_PACKAGES_PATH}/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL",
                "${env:PORTABLE_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/cores/arduino",
                "${env:PORTABLE_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/variants/gamebuino_meta",
                "${env:PORTABLE_SKETCHBOOK_PATH}/libraries/Gamebuino_META/src",
                "${env:PORTABLE_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/libraries/SPI"
            ],
            "browse": {
                "path": [
                    "${workspaceFolder}",
                    "${env:PORTABLE_PACKAGES_PATH}/arduino/tools/CMSIS/4.5.0/CMSIS/Include",
                    "${env:PORTABLE_PACKAGES_PATH}/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL",
                    "${env:PORTABLE_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/cores/arduino",
                    "${env:PORTABLE_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/variants/gamebuino_meta",
                    "${env:PORTABLE_SKETCHBOOK_PATH}/libraries/Gamebuino_META/src",
                    "${env:PORTABLE_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/libraries/SPI"
                ],
                "limitSymbolsToIncludedHeaders": true
            },
            "forcedInclude": [
                "${env:PORTABLE_PACKAGES_PATH}/gamebuino/hardware/samd/1.2.2/cores/arduino/Arduino.h",
                "${env:PORTABLE_SKETCHBOOK_PATH}/libraries/Gamebuino_META/src/Gamebuino-Meta.h"
            ]
        }
    ],
    "version": 4
}
@Pharap

This comment has been minimized.

Copy link

@Pharap Pharap commented Jul 2, 2019

@bfxdev

"${env:USERPROFILE}/Documents/Arduino"

Not everybody has their Arduino folder located there for the record.

@bfxdev

This comment has been minimized.

Copy link

@bfxdev bfxdev commented Jul 3, 2019

@Pharap you're totally right, and it is unfortunate there is no way to determine the sketchbook path from the extension (which seems to be determined internally). I'll write a feature request.

@iFreilicht

This comment has been minimized.

Copy link

@iFreilicht iFreilicht commented Jul 8, 2019

It's also about defines, the ARDUINO macro is not defined, add

defines: [ "ARDUINO=100" ],

to your c_cpp_properties.json

I'm assuming you're using this DHT.h, and your ARDUINO version is 100, change it if necessary.

This is a good workaround.

For a complete fix, this can not be part of the c_cpp_properties.json, as it may change when the user installs a new version of the IDE, and some libraries may rely on that value for compatibility reasons.

@rsheptolut

This comment has been minimized.

Copy link

@rsheptolut rsheptolut commented Jul 8, 2019

Not sure if this was mentioned here (EDIT: I see bfxdev posted a similar workaround, wasn't here yesterday when I was struggling :D so here's a solution that someone can find maybe a bit simpler).
You can work around the issue and gain full intellisense in VS code for your Arduino sketch by fully copying compiler args from Arduino IDE logs, as is, without much thinking.

Full steps:

  1. Open your existing sketch or any other sample in Arduino IDE. Make sure it works, compiles and uploads from there.
  2. Go to File -> Preferences. On the Settings tab in the opened window, tick the Show verbose output during Compilation checkbox.
  3. Next, do Sketch -> Verify/Compile. This should successfully compile your sketch, as expected. You should see a message in the output log along the lines of "Sketch uses X bytes (Y%) of program storage space.".
  4. Copy everything from that same log window below the Arduino text editor and paste it into a real text editor of your choosing.
  5. Find a line there mentioning "ino.cpp" (if several, pick the last of the first bunch). Copy almost the entire line, starting with the path to the g++ compiler and ending with the last include (before the full path to your "ino.cpp" file).
  6. Open the sketch folder in VSCode. Make sure you already have the Arduino extension fully installed there.
  7. Run the >Arduino: Initialize VSCode command (by pressing Ctrl+P and entering the command).
  8. This will generate a .vscode folder with two files.
  9. Replace the entire contents of the .vscode/c_cpp_properties.json file with:
{
    "configurations": [
        {
            "name": "Arduino",
            "windowsSdkVersion": "10.0.17763.0",
            "compilerPath": "{EVERYTHING THAT YOU COPIED FROM THAT LOG}",
            "cStandard": "c11",
            "cppStandard": "c++11",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}
  1. Make sure you escape all the quotes in the pasted string as needed for them to be included in JSON. My working example for a TinyScreen+ board:
{
    "configurations": [
        {
            "name": "Arduino",
            "windowsSdkVersion": "10.0.17763.0",
            "compilerPath": "\"C:\\Users\\evilk\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\\4.8.3-2014q1/bin/arm-none-eabi-g++\" -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -DF_CPU=48000000L -DARDUINO=10809 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD -D__SAMD21G18A__ -DUSB_VID=0x03EB -DUSB_PID=0x8009 -DUSBCON \"-DUSB_MANUFACTURER=\"TinyCircuits\"\" \"-DUSB_PRODUCT=\"TinyScreen+\"\" -DUSBCON \"-IC:\\Users\\evilk\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\CMSIS\\4.5.0/CMSIS/Include/\" \"-IC:\\Users\\evilk\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\CMSIS-Atmel\\1.1.0/CMSIS/Device/ATMEL/\" \"-IC:\\Users\\evilk\\AppData\\Local\\Arduino15\\packages\\TinyCircuits\\hardware\\samd\\1.0.8\\cores\\arduino\" \"-IC:\\Users\\evilk\\AppData\\Local\\Arduino15\\packages\\TinyCircuits\\hardware\\samd\\1.0.8\\variants\\tinyscreen_p\" \"-IC:\\Users\\evilk\\Documents\\Arduino\\libraries\\TinyScreen\" \"-IC:\\Users\\evilk\\AppData\\Local\\Arduino15\\packages\\TinyCircuits\\hardware\\samd\\1.0.8\\libraries\\SPI\" \"-IC:\\Users\\evilk\\AppData\\Local\\Arduino15\\packages\\TinyCircuits\\hardware\\samd\\1.0.8\\libraries\\Wire\"",
            "cStandard": "c11",
            "cppStandard": "c++11",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

This is a manual approach to each individual board / sketch AND depends on hardcoding your PC's paths, but should be OK for one-man projects and only takes a few minutes to set up and allows you to not even get into the weeds of the c_cpp_properties.json format and still gives you full intellisense without hunting down rogue DEFINEs and INCLUDEs. You can be sure that the intellisense run is exactly the same as the real compilation step performed by the Arduino IDE (which I think what vscode-arduino is calling when you run >Arduino: Upload or >Arduino: Verify. Definitely not a replacement for a real solution, but hopefully will save someone some time.

@Hi007

This comment has been minimized.

Copy link

@Hi007 Hi007 commented Aug 13, 2019

hi there,

I'm a newbie playing with MXchip and going through DPS tutorial https://docs.microsoft.com/en-us/azure/iot-dps/how-to-connect-mxchip-iot-devkit. I get the error "include file not found in browse.path." for 4 include files..

Seems like this thread talks about Tag Parser however I couldn't find c_cpp_properties.json.

I'm using VS code 1.37.0 and MXchip with 1.6.2 firmware.

Can someone be kind to provide step by step instructions to fix this problem to get to fun stuff?

Thanks!

@haizaar

This comment has been minimized.

Copy link

@haizaar haizaar commented Sep 27, 2019

It will be great to have "ARDUINO=<VERSION>" in defines by default to safe the frustration about missing WProgram.h includes.

P.S. If you start getting errors about Serial being undefined, try defining USBCON as well (source)

@timaker

This comment has been minimized.

Copy link

@timaker timaker commented Oct 3, 2019

Disable extensions “C/C++ Clang Command Adapter“

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.