Full disclosure, I don’t work for Microsoft (or M$ if you insist) or own any MSFT. I really don’t have a hidden agenda pimping Visual Studio Code, I just happen to like the IDE. If your gut instinct response is “vi/emacs is my IDE!!11!oneoneone”, please don’t bother responding with that (and starting a flame war between the two camps if nothing else ). IDE’s ultimately save me time, and if you’re cool working in (admittedly powerful) text editors, more power to you. That said, if you notice any bad C++ below, PLEASE feel free to comment on that. I did most of my C++ in the bad old days (early 90’s). The modern C++ stuff (11 and up) is still something I haven’t really integrated into my workflow.
I’ve been playing around with some ESP32’s recently and using the Arduino toolset to work with them. FWIW, this isn’t the only option when working with ESP32’s (or ESP8266’s etc.), but I figured I was more comfortable with this framework than others. It’s possible I’m missing out on some things not in their Arduino framework (yet?), but I’ll cross that bridge if I ever bump up against it. In theory the code I am writing is more portable since it’s in Arduino as well.
When doing a lot of work in the Arduino IDE, I find myself getting frustrated with missing “nice to haves” in other IDEs. To that end, I decided to look at the Arduino Extension for Visual Studio Code.
For those not familiar, Visual Studio Code is a lightweight IDE that supports all sorts of languages via extensions you can install. I actually use it at work for some other languages (mostly Go and Python). It’s free (as in beer ) and cross platform (Windows/Linux/Mac).
Here are some of the highlights for how it looks (I’m using a dark theme):
Hitting F1 and filtering for Arduino shows some of the commands it adds:
The current Arduino specific settings are stored in a file inside of the .vscode directory (hidden by default on some OS’s due to name) called arduino.json:
Arduino is C++, so a lot of getting it to work perfectly involved telling it things about the type of C and C++ I was using. It also needs to know where a lot of the header files are located for the project you’re working on. This also gets stored in the .vscode directory in a file called c_cpp_properties.json. Since a lot of the settings I was doing were very ESP32 specific, I created a section with that name. This same file could contain other targets like Win32, Linux, etc. Getting this file configured correctly so that there were no “red squiggles” for undefined things in the editor was the main reason I decided to write this post:
Obviously once you’re in this IDE, there are other things that potentially get easier from other extensions. If you’re in a directory with a .git folder in it, it will suddenly recommend git integration (which works well IMO).
If anyone tries this and runs into problems, feel free to ping me.