1

I added the Adafruit_GFX_Library to my Windows. I used Arduino IDE, Tools > Manage Libraries > Install.

In preferences, Sketchbook location is set to d:\Alex\Hobbies\Electronic\Learning Arduino\Source, so it created the libraries/ folder and the libraries/Adafruit_GFX_Library with the Adafruit_GFX.h file and all the rest.

In the sketch I can use #include <Adafruit_GFX.h> and it works for Arduino IDE.

The problem is with Visual Studio Code and the Arduino extensions.

I have added "${workspaceFolder}/Source/libraries/Adafruit_GFX_Library" to the "includePath" list of the c_cpp_properties.json file.
It solved the problem with VS Code Intellisense that cannot find the library otherwise. Good.

Now I have the same problem ("No such file or directory") when I try to Upload (= build + write to Arduino board), it says:

fatal error: Adafruit_GFX.h: No such file or directory

I tried to use a relative path: #include "../libraries/Adafruit_GFX_Library/Adafruit_GFX.h" but it does not work either (Intellisense is fine):

fatal error: ../libraries/Adafruit_GFX_Library/Adafruit_GFX.h: No such file or directory

What path should I use ?

I added the full path too in the includePath:

"${workspaceFolder}/Source/libraries/Adafruit_BusIO",
"${workspaceFolder}/Source/libraries/Adafruit_GFX_Library",
"${workspaceFolder}/Source/libraries/Adafruit_PCD8544_Nokia_5110_LCD_library",
"d:/Alex/Hobbies/Electronic/Learning Arduino/Source/libraries/Adafruit_BusIO",
"d:/Alex/Hobbies/Electronic/Learning Arduino/Source/libraries/Adafruit_GFX_Library",
"d:/Alex/Hobbies/Electronic/Learning Arduino/Source/libraries/Adafruit_PCD8544_Nokia_5110_LCD_library"

Both of them work... because without it, the Intellisense complains about Adafruit_GFX.h not found.

Adding them it complains about Wire.h and SPI.h (not smart enough to look inside the "src" folders), so I also add them:

"C:\\Users\\Alex\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\1円.8.6\\libraries\\Wire\\src",
"C:\\Users\\Alex\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\1円.8.6\\libraries\\SPI\\src",

and Intellisense works!

But not the build (Adafruit_GFX.h not found!).

I tried to have two kinds of include, for Arduino IDE and for VS Code:

#define VS_CODE true // Define VS_CODE to true for Visual Studio Code compatibility (on "build")
#if VS_CODE == true
#include "d:/Alex/Hobbies/Electronic/Learning Arduino/Source/libraries/Adafruit_BusIO/Adafruit_I2CDevice.h" // required by Adafruit_GFX.h
#include "d:/Alex/Hobbies/Electronic/Learning Arduino/Source/libraries/Adafruit_BusIO/Adafruit_SPIDevice.h" // required by Adafruit_GFX.h
#include "d:/Alex/Hobbies/Electronic/Learning Arduino/Source/libraries/Adafruit_GFX_Library/Adafruit_GFX.h" // Include the Adafruit GFX library
#include "d:/Alex/Hobbies/Electronic/Learning Arduino/Source/libraries/Adafruit_PCD8544_Nokia_5110_LCD_library/Adafruit_PCD8544.h" // Include the Adafruit PCD8544 library for Nokia 5110 LCD 
#else // Arduino IDE is using "magic" names and able to resolve hte libraries path itself
#include <Adafruit_GFX.h> // Include the Adafruit GFX library
#include <Adafruit_PCD8544.h> // Include the Adafruit PCD8544 library for Nokia 5110 LCD
#endif

Now the VS Code builder can find Adafruit_GFX.h but it contains these two "magic" includes:

#include <Adafruit_I2CDevice.h>
#include <Adafruit_SPIDevice.h>

So, now the error is:

.../Adafruit_GFX.h:12:10: fatal error: 
Adafruit_I2CDevice.h: No such file or directory

I added also these two includes in my sketch:

#if VS_CODE == true
#include "d:/Alex/Hobbies/Electronic/Learning Arduino/Source/libraries/Adafruit_BusIO/Adafruit_I2CDevice.h" // required by Adafruit_GFX.h
#include "d:/Alex/Hobbies/Electronic/Learning Arduino/Source/libraries/Adafruit_BusIO/Adafruit_SPIDevice.h" // required by Adafruit_GFX.h

but does not work (Adafruit_I2CDevice.h is not found).

I'm struggling to understand how this extension (Arduino Community) ... is supposed to work.

Greenonline
3,1527 gold badges36 silver badges48 bronze badges
asked Jun 7 at 21:43
4
  • 1
    ${workspaceFolder} is your current sketch folder, so the path for the library directory is not correct. The "includePath" path should be D:/Alex/Hobbies/Electronic/Learning Arduino/Source/lirbaries/**. Commented Jun 8 at 0:46
  • 1
    My VS Code project contains the Source folder (where I store the skectches) so I believe it is correct how I used it. Anyway, I added the full path too: "${workspaceFolder}/Source/libraries/Adafruit_GFX_Library" AND "d:/Alex/Hobbies/Electronic/Learning Arduino/Source/libraries/Adafruit_GFX_Library" but still, the intellisense is OK, but not the build (Adafruit_GFX.h not found). So, I believe the build is NOT looking at the c_cpp_properties.json file at all. I'm wondering if the build is more "picky" and doesn't like the "Arduino Learning" path with a space... Commented Jun 8 at 13:07
  • 1
    Replaced Arduino Community extension with PlatformIO IDE extension and all fine. Commented Jun 8 at 20:55
  • 1
    The ** after the library folder tell the VSCode to looks recursively within the libraries folder. You are missing that. Anyway, if you can use PlatformIO, then use it as Microsoft has deprecated the VSCode Arduino Extensions and now it is managed by some volunteers as a Community fork. folks. Commented Jun 9 at 9:40

1 Answer 1

1

I switch to use the Platform IDE extension (I disabled the Arduino Community Edition extension I was using).
I read the documentation and I was able to setup a new project and using the libraries in 1 hour of work at max.
Code is the same of Arduino IDE.
#include {A-LIBRARY-HERE} works fine after adding the library in the lib_deps section of the platformio.ini file.
Intellisense, code completion, Build and Upload seems easier then the other extension but no need to become crazy with setup of project and this extension seems better organized and having more features.

answered Jun 8 at 20:58

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.