The Arduino IDE

 The upcoming version 2 IDE for Arduino C development had me writing some notes on this new desktop tool for my Arduino C book support web pages. I made the effort as it was always possible that there would be a key change that might have made life difficult for new users working through the book. In fact, the changes are largely improvements to the user interface including a nice “intellisense” addition when entering code. The most significant addition seemed to relate to debugging running code on an Arduino board.

A little investigation revealed that the new “debug” facility only applied to a limited range of recent boards and that almost all of those would require the inclusion of some additional third-party test hardware. Only the new Arduino Zero has the capacity to natively support interactive debugging from the IDE. That capacity is probably a sign of things to come but while the Zero has that “Uno” format and thus heritage appeal the overall package leaves me wondering about the “use case”. Apart from the potential for interactive debugging, my venerable Arduino Due knocks spots of the new board for processor speed and memory size.

While “debugging” was on my mind I did add some notes to the book support pages to illustrate how you could interactively debug running C code using Visual Studio or Visual Studio Code. Of course, that would not help in debugging key issues relating to the interaction of code and Arduino hardware but would be a way of resolving a wide range of C or C++ code issues. A previous blog post of mine here on developing a sudoku solving program running on an Arduino included the fact that I had debugged a key issue using Microsoft’s Visual Studio.

The illustration below shows Visual Studio paused at a breakpoint in a C++ class included in the sudoku solving program.


You can download 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). Visual Studio is a great tool for managing large complex projects but can be a bit daunting if you just want to knock up a short program to get something done quickly.

Because that had worked well for me in the past, I had a stab at trying out my preferred desktop IDE for general code development (Visual Studio Code) to develop and test a C program. The next illustration shows a ridiculously simple C program running and paused at a breakpoint to allow the inspection of a variable. Setting up Visual Studio Code to write, compile and run C/C++ code was a tad more complex than setting up Visual Studio to do the same thing but was worth the effort I thought.


You could download and install VS Code from https://code.visualstudio.com/Download 
which might meet your needs for general code development. I use it for Python, JavaScript, HTML and CSS and I was wondering if it would make an effective IDE for Arduino C programming with the available plugin. I wondered how it would stack up against the new Arduino IDE (version 2).

VS Code for C/C++ development

Not required for Arduino projects but quite possibly of interest; you can read how to set up VS Code for C/C++ code development at https://code.visualstudio.com/docs/languages/cpp although there are a couple of points I should add to help get you up and running.

If you are using a Windows PC you will need a C++ compiler – despite maybe having one built into an Arduino IDE installation. Download the MinGW installer and follow the installation steps. The VS Code web page mentions a key step 7 – but in fact this is step 6  on the referenced MSYS2 web page. You need to copy the “pacman -S mingw-w64-x86_64-gcc” line into the MSYS2 terminal window that is displayed when the installation is complete. Execute the “pacman” command and the required toolset will be installed.


Ignore step 7 on the MSYS2 web page as you should go back to the VS Code page and append the MinGW complier to your “path” environment setting. Then you can check all is well from a new terminal window. [Either a new instance of Windows Command Prompt or a new terminal tab in VS Code.] If all is good then you can go ahead and create your first C++ program – perhaps the suggested “Hello World”.

Follow the suggested way to build the program which will create a new (for example) helloworld.exe file in your VS Code project folder. To execute the program though, I would suggest using the “Start Debugging” option under the “Run” menu (or use the <F5> key). You can set break points in your program to stop the execution at any point, maybe inspect a variable and then step on through the code.


VS Code extension for Arduino development.

To use VS Code for Arduino development you first have to have installed the Arduino IDE as that will still supply the toolset required to build and upload your programs.

Use the VS Code extensions dialogue to install the Arduino extension supplied by Microsoft.


Then use the settings dialogue (filtered by Arduino) to set the path to your Arduino installation. I decided to use the original V1 IDE installation which was a good choice as V2 is not yet supported (but a review of the project github shows this is likely to be available when the new IDE release version ships).

It takes a little clicking around and a few “mouse hovers” to locate all of the tools and settings but once your target board and port are set it is quite straight forward to compile and upload an Arduino program from VS Code.

The VS Code “dark mode” looks good as does the code colour highlighting. For my money, the intellisense is slicker in VS Code but, to be fair, the new IDE is still in early days. The “PROBLEMS” tab quickly shows up syntax errors and omissions – acting as a “linter”. 


Downsides? Well, an obvious one is that the VS Code version of the Serial Monitor is one way only. It collects output but you can’t interact with the code running on a board. I hit this testing the second program from the first chapter in my book (see image above). Fortunately, the solution was simple – fire up that brilliant communications multi-tool putty. In its simplest mode, any key pressed is sent straight to the connected port – no button required. [Don’t forget to close the VS Code Serial Monitor, if it is open, before attempting to connect putty to the same port.]




Putty is a great tool to have available in any case and it can be downloaded from https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

It is worth noting that the VS Code extension for Arduino development appears to offer debugging support although (obviously) with the same limitations and caveats as the version 2 Arduino IDE.

What am I going to choose between the new Arduino IDE and Visual Studio Code? I suspect that I will switch back and forth for a while to see which one sticks.


Comments

Popular posts from this blog

Unicode output from an Arduino.

Arduino: How to scroll long text on OLED screen

Arduino Regular Expressions