I'm working on a little project with a NodeMCU, fairly typical temperature sensor type of thing reporting in to my own web service.
I got the basics of it working just fine using the Arduino IDE, but I decided to I wanted a more powerful editor, so I moved over to using Visual Studio Code. It works fine, the sketch opens, compiles, and uploads to the board with no issues. VS Code is a vastly better editor than the Arduino IDE could ever be.
Except VS Code flags 2 identifiers as unknown.
Firstly the U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C for the display, and also D7 as a pin definition. In both cases I can mouse over the identifier, press F12, and it will correctly show me the definition from the appropriate header file. (Oddly, for the D7 definition in pins_arduino.h it also marks uint8_t as undefined but will also show its definition when I press F12)
As I said, despite this the sketch compiles, uploads, and runs just fine. I could ignore the error, but my OCD won't let me. ;)
I have the Arduino for Visual Studio Code from Microsoft v0.2.29 (latest version) extension installed, and ESP8266 Community board definitions v2.6.3 installed. I'm using the U8g2 library by Oliver, v 2.27.6.
Anyone got any ideas on this?
Had the same problem, looks like the problem is that unlike default Arduino IDE, this extension does not include bare minimum libraries needed to work with Arduino Files. So I had to manually include Arduino.h
#include <Arduino.h>
Then you have to locate your pins_arduino and add its location to includePath. Something like this, Change includePath in c_cpp_properties.json to this:
"includePath": [
"C:\\Users\\[USER]\\AppData\\Local\\Arduino15\\packages\\esp8266\\tools\\**",
"C:\\Users\\[USER]\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.6.0\\**",
"C:\\Users\\[USER]\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.6.0\\variants\\ESPDuino"
],
Hope this solves your problem.