Arduino Debugger



Introduction¶

Get started with Arduino and ESP32-DevKitC: debugging and unit testing¶. The goal of this tutorial is to demonstrate how simple it is to use VSCode to develop, run and debug a simple project with the Arduino framework for the ESP32-DevKitC board. When I first heard of the SPI interface on the Arduino, I thought that would make a great way to debug. As anyone who has used Serial.println knows, even at speeds of 115,200 baud, data can take quite a few cycles to get out there (as a rough rule of thumb, divide the baud by 10 to get bytes/second, so at this high speed we still only get 10k chars out max per second).

Since 2.1.0-rc1 the core includes a Debugging feature that iscontrollable over the IDE menu.

The new menu points manage the real-time Debug messages.

Requirements¶

For usage of the debugging a Serial connection is required (Serial orSerial1).

Arduino Debugger

The Serial Interface need to be initialized in the setup().

Set the Serial baud rate as high as possible for your Hardware setup.

Arduino

Minimum sketch to use debugging:

Usage¶

  1. Select the Serial interface for the Debugging messages:

  2. Select which type / level you want debug messages for:

  3. Check if the Serial interface is initialized in setup() (seeRequirements)

  4. Flash sketch

  5. Check the Serial Output

Informations¶

It work with every sketch that enables the Serial interface that isselected as debug port.

The Serial interface can still be used normal in the Sketch.

The debug output is additional and will not disable any interface fromusage in the sketch.

For Developers¶

For the debug handling uses defines.

The defined are set by command line.

Debug Port¶

The port has the define DEBUG_ESP_PORT possible value: - Disabled:define not existing - Serial: Serial - Serial1: Serial1

Debug Level¶

All defines for the different levels starts with DEBUG_ESP_

Arduino Debugger

a full list can be found here in theboards.txt

Studio

Example for own debug messages¶

The debug messages will be only shown when the Debug Port in the IDEmenu is set.

Arduino Debugger

As every Hackaday reader knows, and tells us at every opportunity in the comments, adding an Arduino to your project instantly makes it twice as cool. But what if, in the course of adding an Arduino to your project, you run into a problem and need to debug the code? What if you could use a second Arduino to debug the first? That would bring your project up to two Arduinos, instantly making it four times as awesome as before you started! Who could say no to such exponential gains?

Not [Wayne Holder], that’s for sure. He writes in to let us know about a project he’s been working on for a while that allows you to debug the execution of code on an Arduino with a second Arduino. In fact, the target chip could even be another AVR series microcontroller such as a the ATTiny85. With his software you can single-step through the code, view and modify values in memory, set breakpoints, and even disassemble the code. Not everything is working fully yet, but what he has so far is very impressive.

The trick is exploiting a feature known as “debugWIRE” that’s included in many AVR microcontrollers. Unfortunately documentation on this feature is hard to come by, but with some work [Wayne] has managed to figure out how most of it works and create an Arduino Sketch that lets the user interact with the target chip using a simple menu system over the serial monitor, similar to the Bus Pirate.

[Wayne] goes into plenty of detail on his site and in the video included after the break, showing many of the functions he’s got working so far in his software against an ATTiny85. If you spend a lot of time working on AVR projects, this looks like something you might want to keep installed on an Arduino in your tool bag for the future.

Arduino Debugger Software

Debugging microcontroller projects can be a huge time saver when your code starts running on real hardware, but often takes some hacking to get working.