How to configure Visual Studio Code includePath for Arduino and Teensy
Asked Answered
B

2

14

I'm working with Arduino and Teensy boards from inside VS code. I can build and program everything fine, but the highlighting and code following functions built into VS Code don't work.

Previously, my custom headers weren't loading or highlighting, but this answer got that working for me. Now I have the right libraries on my include path (and I can click and follow them to the correct source) but some names still don't work:

enter image description here

enter image description here

My includePath appears to be configured correctly, as I mentioned I can follow the includes and it opens the correct sources:

"includePath": [
    "${workspaceFolder}/**",
    "C:/Program Files (x86)/Arduino/**",
    "C:/Program Files (x86)/Arduino/hardware/teensy/avr/cores/teensy/**",
    "C:/Program Files (x86)/Arduino/hardware/teensy/avr/libraries/ADC/**",
    "C:/Program Files (x86)/Arduino/hardware/arduino/avr/cores/arduino/**",
    "C:/Program Files (x86)/Arduino/hardware/arduino/avr/variants/standard/**",
    "C:/Program Files (x86)/Arduino/hardware/tools/avr/lib/gcc/avr/5.4.0/include/**"
]

I can confirm the header is on the includePath and has the names defined I'm looking for:

enter image description here

Somehow VS Code is still saying the identifier is undefined.

Any ideas?

Bumpy answered 6/5, 2020 at 20:6 Comment(2)
You might want to have a look at VisualTeensy github.com/luni64/VisualTeensy/wiki/Quick-Start-Guide. It generates all required vsCode files for Teensy projects. Even if you don't want to use it, it has a life display of the generated files so you can easily experiment with Teensy settings and watch the effect on generated files.Coypu
How are you adding IncludePaths for compilation/building?Bacchic
J
6

Just install the Arduino extension and run vscode command Arduino: initialize. You will need to select board and

File .vscode\c_cpp_properties.json and .vscode\arduino.json will automatically created.

Jaguar answered 19/3, 2022 at 16:49 Comment(6)
Doing this does not update the include path for the installed Arduino libraries. In my case I have a standalone portable installation and need to get the include path updated to include that location.Wan
@RyanHiggins This works with normal installation and arduino cli as well.Jaguar
This works! I'd add just one more thing, for newbies like me, you have to change the C/C++ Configuration from "Win32" to "Arduino" in the bottom rightManchukuo
What if I want my own include path to my own libs?Bacchic
My c_cpp_properties file wouldn't be updated by the extension until I deleted it and reran the initialize command.Unconformable
@E.Morell You can control that behavior with settings key "intelliSenseGen" ("enable"|"disable"|"global") per project in .vscode/arduino.json. Alternatively, you can set the default for all projects in your global user settings with a slightly different key "arduino.disableIntelliSenseAutoGen" (true|false)Berget
M
2

As mentioned by others: install the Arduino extension and run Arduino: initialize to generate the .vscode\arduino.json file.

Now, .vscode\c_cpp_properties.json should also be created, but if it isn't, You can run Arduino: verify (or just Arduino: upload) to generate/update it.

Also, in my case the extension complained when the main .ino file name didn't match the folder name, regardless of the "sketch" field in arduino.json.

Magnanimity answered 15/3 at 19:8 Comment(2)
Your answer should stand on its own without relying on others. Currently there are three deleted answers to this question; if the one you've mentioned gets deleted, will your answer still make sense? (Of course, if you use information from another answer, you should also properly attribute it.)Ethical
@Ethical right thx, I modified it a bit.Magnanimity

© 2022 - 2024 — McMap. All rights reserved.