The new version 2 Arduino IDE features support for debugging running code on an Arduino board. However, this is only available for a selected list of recent boards and almost all require the intervention of some fairly expensive third-party test and development hardware. The only board that currently supports IDE2 debugging “natively” is the Arduino Zero.
I took a look at the specs for the Zero but did not find them very compelling. Continued support for the Uno format with a 32bits processor is a positive but the package is slower and has less memory than the much older Due. Comparisons to the offerings of the Raspberry Pi project hardware continue to make mildly dispiriting reading. The ability to manage some debugging of a running program on the Zero looked interesting but frankly felt a little beyond the scope of this book.
I have occasionally felt the need to debug some more complex Arduino C code where just providing feedback to the Serial Monitor failed to solve a problem. See my blog post on writing an interactive Sudoku solving program running on a MKR WiFi 1010 board for an example.
On that occasion I ported my code to Microsoft’s Visual Studio to resolve the issue as I was able to “step” through the code and inspect variables as the program ran.
The image below shows the Visual Studio IDE stepping through the sudoku program and inspecting the mSize variable inside a C++ class method (C++ classes turn up later in the book).
Various versions of that sudoku solving program (available to run on a range of Arduino hardware) can be inspected and downloaded from github.
If you get in a similar jam then you might like to install the free Microsoft Visual Studio community edition During the set-up you can specify C/C++ as your target project type (along with any others on the list that take your fancy).
If you are already a Visual Studio Code user (I use VS Code variously for JavaScript, HTML, CSS and Python development) you can set up that excellent IDE for the C programming language. If you are not already a VS Code user but would prefer a “lighter” solution to the full Visual Studio installation then then you can download and install VS Code from https://code.visualstudio.com/Download Be warned though, that the set-up and later compilation of C programs using VS Code is a more complex process compared to using the tightly integrated Visual Studio.
You can read how to set up a VS Code C/C++ development environment here https://code.visualstudio.com/docs/languages/cpp
The image below shows a code break point and the inspection of a variable during the execution of a simple “Hello World” C/C++ program using VS Code.
Ignoring the debugging issue, you can, of course, use VS Code or Visual Studio as an alternate IDE for Arduino development and there are VS Code and Visual Studio extensions to support this. You have to have the standard Arduino IDE installed as well; as that provides the toolchain for compiling and building your Arduino C programs. This has its attractions and some Arduino developers might prefer the support offered by these heavy hitters even when compared to the Arduino IDE2. I think I will duck that debate here though and leave you to explore the options (if you want) after finishing this book.