Using libraries with VS code Arduino extension

Hi, I've been trying to get VS code to detect my arduino libraries for 2 weeks now and it still won't work. I've tried pretty much everything from changing the default C compiler to the include path JSON settings. I'll attach some photos so you can see the issue.


This photo shows that some libraries work, but the majority of the libraries that I've imported don't work.

This is a picture of the JSON settings, and I'll try and attach the file as well.

#include <Arduino.h> 
#include <Adafruit_BMP280_Library> 
void setup() 
{
    Serial.begin(9600); 

}
void loop()
{
    
} 

Welcome to the forum

Is there a particular reason why you want to use VS Code rather than the Arduino IDE ?

I use VS code regularly for Java coding and wanted to use just one IDE. I'm also working on a project that uses serial data from an arduino.

Hi @murrconn0361. I don't have any experience with the Arduino support for VS Code, so I won't be able to provide assistance, but I think the other forum helpers will benefit from knowing which of the various VS Code extensions you are using to add Arduino support to your VS Code.

I am aware of these extensions:

That’s a great point, I’m using the arduino community edition extension for VS code

The message says 'cannot open source file'. Either the library isn't installed, or there is a permissions error.

1 Like

I have all the libraries installed, and they're in the workspace folder, and I don’t know if it could be a permissions error or not.

If you read the pinned post 'How to get the most from the forum', you might learn what you need to do in order that the helpers can help.

The code and error log are supposed to be posted in code tags. Those image files are of no use to us.
Remove _Library and you will be ok.

I use Arduino support in VS code and I don't have any problem with libraries.
First, you need a regular Arduino installation to use Arduino VS extension . And you have to install a library in your Arduino libraries folder.

Perhaps it is the issue.
You must install the libraries in Arduino libraries folder, not in workspace

Ok, I had copied my libraries from the Arduino folder into the workspace folder in an attempt to make it work, and it didn't make a difference. I'll try uninstalling the libraries and reinstalling them.

Remove the word _Library from the include statement.
Change this
#include <Adafruit_BMP280_Library>
to this
#include <Adafruit_BMP280>

...and ADD the .h extension:

#include <Adafruit_BMP280.h>

because an include statement MUST POINTS to the file rather than to the folder.

2 Likes

OOPS. Forgot, double-click select doesn't pick up the extension.

Ok, so I reinstalled the library and changed the include statement, but it's still giving me errors. The first error is #include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (C:\Users\conno\Documents\Grade 11 Summative Project\WeatherStation\WeatherStation.ino).C/C++(1696) and the second error is cannot open source file "Adafruit_BMP280.h"C/C++(1696)

I also deleted the copy of the library folder from the workspace. The Libraries seem to be installing themselves in the 'Arduino' folder in 'Documents'

Don't tell us, show us, place the verbose compiler output in code tags.

Ok sorry I'll do that next time, the libraries are working now! Thanks for all of your help.

1 Like