Maybe Consider Using Visual Studio Code for Arduino Development?

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 :slight_smile:). 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 :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:
image

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.

9 Likes

I have taught over 50 Arduino-ish classes at DMS with the Arduino Nano, Wemos D1 Mini ESP8266 and ATtiny using the Arduino IDE. I chose to try to pull folks into the fun electronics/microcontroller hobby using the Arduino IDE which I see as the best IDE for beginners. At least, it seems to be the IDE used in most intro documents and youtubes for beginners.

It would be great if you would develop and teach classes using Visual Studio. I’ll be first to sign up if you offer a class.

8 Likes

Yeah, that’s probably a fair assessment. A bigger IDE might feel like looking at the knobs and switches on a 747. :laughing:

Just to be clear, “Visual Studio” and “Visual Studio Code” are actually two different products. “Code” is completely free (again, as in beer at least), but there is also a free (Community) version of “Visual Studio”. The “Code” product is much lighter and more modular in some ways.

This is the first time I have messed with the ESP chips. I am trying to put together a small RESTful JSON web service for a project. A joke I make at work is creating a web service is so easy, you can accidentally do it. That’s almost true for some of the frameworks we use, but it’s a much different challenge in a microcontroller :laughing:.

3 Likes

This was a text messages I sent to a group of friends the other day. We were discussing code editors.

My thoughts on Visual Studio Code. If I hadn’t already known, In a million years I would have never guessed this was an MS product. Especially being open source and the look and feel. I have been using it daily since last Monday. Great product. I can’t compare it to Sublime as I hardly used it. Impressed as hell with the abilities out of the box, with extensions it’s even better. Finding the right extensions is key.

VSCode is a pretty decent tool. Hadn’t even dawned on me to try it for Arduino. Course, I haven’t written much Arduino code lately.

2 Likes

I switched over to visual studio code with platformio for my esp32/esp8266 after marlin 2.0 came out for the 3d printers. I haven’t looked back. I’ve also started using it for my vagrant and python scripting. It’s not bad.

2 Likes

IDE?

I just type “make” followed by “load” into GDB. :slight_smile:

See how I didn’t turn it into a flame war. :wink:

There’s a VSCode plugin for that :stuck_out_tongue_closed_eyes:

1 Like