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.
1 Answer 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.
${workspaceFolder}
is your current sketch folder, so the path for the library directory is not correct. The "includePath" path should beD:/Alex/Hobbies/Electronic/Learning Arduino/Source/lirbaries/**
.**
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.