1

I am currently trying to control a servo from an Arduino for a laser turret through vscode. the problem is that vscode does not pick up on my library folder called <servo.h>. I have a folder named "workspace" with the servo library, the .ino file, and the workspace file for vscode.

Instead of platformIO, I'm using the Arduino extension for vscode. I'm using an Arduino UNO. here is the code so far:

#include <Servo.h>

Servo servo1;
Servo servo2;
int potval
int potpin = 0

void setup()

and here is what my c_cpp_properties.json file looks like:

{
    "configurations": [{
        "name": "Win32",
        "includePath": [
            "${workspaceFolder}
        ],
        "defines": [
            "_DEBUG",
            "UNICODE",
            "_UNICODE"
        ],
        "cStandard": "c17",
        "cppStandard": "c++17",
        "intelliSenseMode": "windows-msvc-x64"
    }],
    "version": 4
}

And I'm running Windows 10

paulsm4
  • 114,292
  • 17
  • 138
  • 190

2 Answers2

1

Although this topic is open for quite some time, a better solution could be as follows:

  1. Check if the libraries you want to include are actually installed. You can use Library Manager of the Arduino IDE. This tool also helps you to update the libraries if new releases are available.

  2. Ideally, you should know where these libraries actually are on your file system. On Windows, they might be located in the Arduino IDE installation folder or in your User directory. On a Mac, they are either in /Users/<username>/Library/* or /Applications/Arduino.app/Contents/Java/libraries/*.

  3. In order to properly use the includes in Visual Studio Code so that they are recognized, you can extend the array includePath in your configurations in the c_cpp_properties.json file. You can add the paths mentioned above.

In short, the result could look as follows:

{
"version": 4,
"configurations": [
    {
        "name": "Arduino",
        "includePath": [
             "/Your/first/added/library/",
             "/Your/second/added/library/with/subfolders/**",
        ]
     }
  ]
}

Afterwards, you can include the libraries as follows:

#include <Arduino.h>
#include <Servo.h>
    
// your code goes here
MichaelHuelsen
  • 386
  • 1
  • 4
  • 11
-3

Any local library file that is included must use "" instead of <>.
#include <Servo.h>
should be replaced with
#include "Servo.h"
Here is a post describing the difference between the two:
What is the difference between #include < filename > and #include “filename”?

David Ryan
  • 10
  • 2
  • If VScose is set up properly for Arduino, the angle brackets actually work. I use them all the time for external libraries. – lurker Jun 24 '21 at 02:48