I'm always looking for the most productive way to get my work done. When I'm in software-engineer mode, my familiarity with the features of my development environment play a huge role in that efficiency. My favorite integrated development environment (IDE) varies by programming language, but, increasingly -- whether I'm programming in C/C++, Javascript or Python -- I try to find any excuse I can to use Visual Studio Code.
VS Code (not to be confused with Visual Studio) is a free, open source code editor supported by Microsoft. It has a long list of features including powerful key-bind-ability, file navigation, extensions to support just about any language and a pleasantly modern UI.
I've used VS Code as my IDE for platforms ranging from the nRF52840 and the C-based nRF5 SDK to a Raspberry Pi running Python scripts. However, a big chunk of the software development we do here at SparkFun revolves around Arduino, which usually means utilization of the Arduino IDE. Compared to VS Code, the Arduino IDE's feature-set is limited -- there's basic syntax highlighting, auto formatting, and line numbering, but not much more. It's missing modern IDE features like:
Until recently, beyond exploring Arduino's "Use External Editor" preference, there wasn't much to be done to add more functionality to the Arduino development workflow. That all changed with the release of Arduino CLI.
Arduino CLI is a command-line software tool that features board and file management functionality plus compilation and programming tools. Whether you want to download a new Arduino library or upload a compiled Arduino sketch to a RedBoard, the Arduino CLI is there for all of your scripting and command-lining needs. Taking it a step further -- combined with an IDE or editor (like VS Code) -- Arduino CLI can become an integral part of a powerful, DIY Arduino sketch, library, and core development environment.
To document this pairing, I wrote up a quick tutorial:
The tutorial explains how to pair VS Code with Arduino CLI to get the best of both development worlds: a modern IDE and the simplicity of Arduino's API and board support.
For all those looking at doing Arduino in Visual Studio Code, check out the Arduino Extension: https://marketplace.visualstudio.com/items?itemName=vsciot-vscode.vscode-arduino @JIMBLOM
I read through your tutorial and it looks like VS code could makes things easier, if the task file is unique to each project (sketch). Using the Arduino IDE is a real pain moving from project to project, with different boards, com ports, etc.
I've been using VS Code and PlatformIO for about a year. Is this better?
Thanks for the post! I'll have to check out the stuff you've suggested!
I've been "doing" software since shortly after Neil Armstrong took his "one small step"! (At least we no longer have to punch paper cards for our programs...)
I've always thought that the Arduino API is a real "blast from the past" -- it has the feel and capabilities from APIs from the late 1970s, albeit using C++ (which is more recent). For something intended for "newbies" to use, it's missing what I consider to be the most instructive feature -- the ability to single-step through the program. (True, the ATmega328 lacks hardware support for single-stepping, but it is possible to support single-stepping purely in software, though it's not easy to develop.) Single-stepping, especially when combined with "variable watch", can be VERY instructive as to what's going on in the program for the beginner. (It can also be very useful for the more experienced programmer, especially in tracking down those "dumb mistakes" that we all make!). The micro:bit's simulator can be helpful in this regard, but simulators can have problems with hardware interfaces.
The other problem I have with the Arduino IDE is that it doesn't have an easy and obvious way to add "-D" options to the gcc command line. This can be very useful for things like ESP8266 programs where one might have, say, three or four processors for sensors that vary only in name (and/or IP address if, like me, you use fixed IPs for your "edge nodes"). At first blush, it looks like the CLI may work in this situation.