Code Walkthrough
Library Setup
To use the Arduino Debugger library, you must:
- Download the code’s zipped folder: link here
- Install the zipped library via the Arduino IDE
- Include the library at the top of your program
#include <Debugger.h>
- Create an Arduino debugger object:
//initialize method signature
static ArduinoDebugger initialize(bool usingFloat, bool isAvr, bool usingTerminal);
//Example configuration for Ardunio Uno
ArduinoDebugger debugger = Debugger::initialize(false, true, false);
The debugger is created via the initialize method. The initialize method requires 3 booleans in order to properly configure the debugger for your setup. The booleans (in order) set the following options:
- true
- allow for float variables to be added to the variable watch. This can use a large chunk of memory and should be set to false if you are using smaller memory boards (UNO) & especially if you are not using floats within your program.
- false
- cannot handle floats (recommended setting to conserver program space)
- true
- the board being compiled for is an AVR based microchip. Some examples would be the Arduino Uno, Arduino Mega, or the Adafruit Circuit Playground Classic.
- false
- the board being compiled for is NOT an AVR based microchip but is instead an ARM based microchip. Some examples would be the Arduino Due, the Micro:Bit, or the Adafruit Circuit Playground Express.
- true
- Serial output will be optimized for terminals that allow for the screen to be cleared.
- false
- Serial output will be configured for the standard Arduino Serial Monitor which does not allow for the screen to be cleared.
After you have included the library and created your debugger, you’ll be set to add your variables to the watch list.
Adding Variables to the Watch List
The Arduino Debugger is able to display the current value of your program’s variables AND update their values, while the Arduino program is still running. But in order for the debugger to do that, you must first tell it which variables you are instead in “watching”. To do this, you will need to call the add() method:
//add method signature
void add(void* var_ptr, Type type, char var_name[]);
//example call to the add method
debugger.add(&var, TYPE, "var");
The add method requires three parameters:
- void* var_ptr
Memory Address - The debugger needs to know where the variable is in memory. To do this in C, we apply an apersand, &, to the front of a variables name. For example if you want the memory address of the variable number,
byte number = 0;
, you would write&number
- Type type
Data Type - The debugger needs to know what type of data the variable is holding. TYPE refers to an enum which has the following options to cover Arduino's data primitives & arrays:
BYTE, BYTE_ARRAY, INT, INT_ARRAY, LONG, LONG_ARRAY, FLOAT, FLOAT_ARRAY, CHAR, CHAR_ARRAY, BOOL, BOOL_ARRAY
Be aware that FLOAT can only be used if the debugger was initailized with usingFloats set to true.
The TYPE enum also provides options to handle arrays, but they require a bit more work. In order to use an array, the debugger must know how many elements are in the array. To provide that information, you'll need to append the _ArraySize to the end of the variable name. For example:
byte numbers[] = {1,2,3};
would be listed as “numbers_3”Notice that Strings are not listed as a valid TYPE. To conserve space, the Arduino Debugger only works with character arrays. In order to pass in a String, you'll need to call the c_str() method instead of using the apersand, &var. For example:
String message = "Hello world"; debugger.add(message.c_str(), CHAR_ARRAY, "message_11");
- char var_name[]
Variable Name - The last parameter is char array that lists the name of the variable. This will be used to identify the variable when the debugger displays its information to the Serial Monitor. This parameter is restricted to a maximum of 14 characters. So if your variable name is too big, you can instead use an abbreviation.
In order to conserve space, the Arduino Debugger's watch list is limited to a maximum of 10 variables. Experienced programs can increase/decrease this variable limit by updating Variable var_watch[10];
, located in the ArduinoDebuger.h file.
Adding a Breakpoint
In order to debug your program, you’ll need to add in a breakpoint. The breakpoint will pause your Arduino program and allow you to check on the current state of your variables & hardware pins. To do this you’ll need to add a call to the breakpoint method:
//breakpoint method signature
void breakpoint(char name[]);
//example call to the breakpoint method
debugger.breakpoint("Identifier");
The breakpoint method has an optional parameter, char name[]. The name is used to identify each breakpoint. So if your program has mutliple breakpoints added, you’ll be able to tell which one you have stopped at.
Main Menu
Once the Arduino program reaches a breakpoint, you will see the debugger’s main menu, via the Arduino Serial Monitor. The menu will allow you to check on the microcontroller’s hardware pins (1) or the variables inside the watch list (2).

Hardware Pins
Selecting “Hardware Pins” will display the current state of your boards digital & analog pins. For digital pins, there are three potential states:
- HIGH
- This means the pin is ON and providing POWER OUT
- LOW
- This means the pin is OFF
- HIGH(Power In)
- This means the pin is receiving POWER IN from an external power source

The analog pins will be displayed next to their current analogRead() values. The resolution or range for these values is dependent on the microcontroller you are using. For example, the Arduino Uno has a potential value between 0 to 1023 and the Arduino Due has a potential value between of 0 - 4095.

Setting a Digital Pin’s State
Besides viewing the current state, you can update a digital pin to either HIGH or LOW. Please note, that you can only update a digital pin’s value. The library does not support modifying analog output (PWM). In the example below you can see digital pin 4 being updated from LOW to HIGH.


Variables
Selecting “Variables” will display the current value of each variable currently on the watch list.
long frequency = 253;
char selection = 'A';
debugger.add(&frequency, LONG, "frequency");
debugger.add(&selection, CHAR, "selection");
If the above variables had been added to the watch list, then the debugger would display the following:

You can update the value of any variable listed by entering it’s index in the watch list. For example, to update frequency you would enter 0



Handling Arrays
The debugger does allow for arrays to be displayed and updated. As noted in the “Adding Variables” section, you will need to format the variable name to denote the array’s size (number of elements).
byte pins[] = {0,1,2};
bool valid[] = {false, true};
debugger.add(&pins, BYTE_ARRAY, "pins_3"};
debugger.add(&valid, BOOL_ARRAY, "valid_2"};
If the above variables had been added to the watch list, then the debugger will display the following:

The debugger will display each value within the array. To update a specific value inside an array, you must first select the array variable. For example, to update valid[1] to false you would enter 1 (select the variable) and then enter 1 (to select the array index):
![Updating valid[1] to false](Arrays_2.png)
![value[1]'s Value Updated](Arrays_3.png)
Example Program
Listed below is an example program using the Arduino Debugger. The program is intended to turn on a series of LEDS connected to an Arduino device, but there is an error located within the for loop that prevents all of the LEDs from turning on. By placing breakpoints within the FOR loop, one can see that the variable i is being incorrectly updated and also see that pins[1] & pins[3] (Digital Pins 4 & 6) are never set to HIGH. The example code should run on any Arduino Board, but you may have to update the pin numbers listed in the variable pins.
#include <Debugger.h>
//Standard debugger configuration for Arduino Uno. If using an ARM processor, set to (false, false, false).
ArduinoDebugger debugger = Debugger::initialize(false, true, false);
void setup() {
Serial.begin(9600);
while(!Serial) {}
}
void loop() {
byte pins[] = {3,4,5,6};//Pins connected to LEDs
byte i = 0;//for loop counter
debugger.add(&i, BYTE, "i");//Add i to variable watch
debugger.add(&pins, BYTE_ARRAY, "pins_4");//add pins to variable watch, Arrays require unique syntax
debugger.breakpoint("Before For Loop");
for(i; i < sizeof(pins)/sizeof(pins[0]); i++){
debugger.breakpoint("Start For Loop");
digitalWrite(i, HIGH);//Turn on the chosen LED
i++;//Error!
debugger.breakpoint("End For Loop");
}
}
