Arduino Debugger
1.0
A C++ Library to add debugging features via the Arduino IDE's Serial Moniter
|
The ArduinoDebugger library provides debugging functionality for the Arduino IDE via the Serial Monitor so that a programmer can view/update the state of variables and hardware pins at runtime. This document will detail how to:
To use the ArduinoDebugger library, you'll need to add it to your Arduino IDE. In the Arduino IDE, select the "Sketch > Include Library > Add .ZIP Library ". A file browser will pop up. Navigate to where you saved the ArduinoDebugger.zip file and select it. Once added, you will now be able to include the ArduinoDebugger library to your program.
To start using the ArduinoDebugger, open the provided example "1_Basic_Setup". You can find it under "Files > Examples > ArduinoDebugger > 1_Basic_Setup".
The code for the example is also included below:
With the Debugger::breakpoint() method, a programmer can pause a running Arduino program and then view the current state of the system. This means the programmer can check or update the current value of variables and hardware pins via the Serial Monitor. Two versions of the breakpoint() method can be used:
The first version requires no parameters. This option is recommended if only 1 breakpoint is being used in the program.
If multiple breakpoints are used, it is necessary to know which one the program has stopped at. To help differentiate between breakpoints, the second version requires a char[] to identify the breakpoint. Here is an example using multiple breakpoints:
The debugger cannot automatically track the variables in a program. Instead, they must be manually added to the debugger using the Debugger::add() method.
The add() method requires three parameters, which are as follows:
Type type (enum) :
The second parameter defines what type of data is being referenced by the variable. This is necessary for the debugger to properly display and update the variable. The second parameter must be one of the values for the enum Type provided by the ArduinoDebugger. The potential values are:
Data primitives: BYTE, INT, LONG, FLOAT**, CHAR, BOOL Arrays: BYTE_ARRAY, INT_ARRAY, LONG_ARRAY, FLOAT_ARRAY**, CHAR_ARRAY, BOOL_ARRAY
The debugger allows a programmer to view the current state of both Digital and Analog Pins. For Analog Pins, the debugger will display a value between 0-1023. Digital Pins have 3 potential states:
In addition to viewing Digital Pin states, the debugger allows the programmer to set a Digital Pin's state to either HIGH or LOW (via the Debugger::breakpoint() method).
Depending on the microcontroller, the full list of all Digital and Analog pins can be a bit overwhelming. It is possible to create a subset of pins to keep track of using the Debugger::setSubsetPins() method.
The setSubsetPins method accepts 4 parameters which are as follows:
Examples of setting subsets of pins:
Breakpoints are great for viewing and updating variables and hardware pins, but pausing/continuing may make debugging more time consuming then necessary. To help display the state of the system in a human readable fashion, across multiple iterations, a programmer can instead use the Debugger::repeat() method.
The repeat method has a simple set of logic:
To determine the number of times repeat() will be called before pausing, a programmer can add in a counter value (default is 3)
Only one call to repeat() is recommended per Arduino Program. If you want more than one repeat point, the Arduino Debugger provides 5 unique counters to work with. Calls to repeat() and repeat(byte value), use the default counter (id 0). To use the other counters, you will need to set call its specific id.
Example Program: