Debugging Arduino firmware with print statements // ifdef, header files, trace
Channel: Sayanee Basu
Date: 2020-09-04

#debugging #print #arduino
We will get to the basics of using a simple debugging technique: the print statements. We will work our way step by step from adding some conditional statements, to adding a header file and finally a library. To toggle the debug flag on and off will still be as simple as commenting on the first line. The original firmware code size will be exactly the same when the debug flag is off. In the end, I share my thoughts on another type of debugging as well as how important it is to incorporate developer happiness in debugging and make it as simple as possible.

⏰ TIMESTAMPS
0:00 Intro
00:30 No print statements
01:33 Add print statements
03:14 Add conditional #ifdef for debug
04:46 Define a function
06:40 Add more info as part of debugging
08:40 Add header file
09:57 Add a library instead
12:56 Add more functions
14:47 My thoughts on using a debugger and developer happiness!

‣ Some links below are affiliate. I receive a small commission at no extra cost to you.

📻 PRODUCTS MENTIONED
RobotDyn SAMD21 M0 Mini https://s.click.aliexpress.com/e/_AZG8aU

🎩 DEMO FILES 
Debugging with #ifdef DEBUG https://hutscape.com/tutorials/arduino-debug
Debugging with ArduinoTrace library https://hutscape.com/tutorials/arduino-trace
Debugging with #ifdef and ArduinoTrace library https://hutscape.com/tutorials/arduino-debug-trace

📺 WATCH NEXT
Arduino CLI and the art of command line https://www.youtube.com/watch?v=cVod8k713_8
Makefiles for using with Arduino https://www.youtube.com/watch?v=Os5sGlw3PV0
6 ways to access the serial monitor https://www.youtube.com/watch?v=UwOLAL9z2Rk
Arduino firmware on ATmega328p or SAMD21 https://www.youtube.com/watch?v=xV1l5SdE8sk

🔗 LINKS SHOWN
Arduino Serial.print() https://www.arduino.cc/reference/en/language/functions/communication/serial/print/
Standard Predefined Macros https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html#Standard-Predefined-Macros 
SAMD21 M0-Mini https://robotdyn.com/samd21-m0-mini.html
ARDUINO ZERO https://store.arduino.cc/usa/arduino-zero
ATSAMD21G18 microcontroller https://www.microchip.com/wwwproducts/en/ATsamd21g18
Arduino Serial communication https://www.arduino.cc/reference/en/language/functions/communication/serial/
Do comments get translated to machine code? https://stackoverflow.com/questions/28950718/do-comments-get-translated-to-machine-code-c
The C preprocessor https://gcc.gnu.org/onlinedocs/cpp/
Arduino millis() https://www.arduino.cc/reference/en/language/functions/time/millis/
GitHub search DebugUtils https://github.com/search?q=DebugUtils
ArduinoTrace library https://github.com/bblanchon/ArduinoTrace
Chrome DevTools debugger for JavaScript https://developers.google.com/web/tools/chrome-devtools/javascript
Arduino Pro IDE https://www.arduino.cc/pro/arduino-pro-ide
GDB and OpenOCD http://openocd.org/doc/html/GDB-and-OpenOCD.html 
The Philosophy of Ruby A Conversation with Yukihiro Matsumoto https://www.artima.com/intv/ruby.html

🔌 TOOLS USED
https://hutscape.com/tools