You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Listen to the same serial port used for debug output to switch Debug Level and other config.
Use VERBOSE, DEBUG, INFO, WARNING, ERROR, NONE or V,D,I,W,E,N. to change debug level, or LABEL, TIMESTAMP, NEWLINE or L,T,N to toggle config settings.
Terminate command with a Line feed ('\n) or CRLF ('\r\n')
This class provides functionality useful for debugging sketches via `printf`-style statements.
9
9
@@ -16,7 +16,7 @@ Arduino_DebugUtils has 6 different debug levels (described descending from highe
16
16
*`DBG_DEBUG` - more information
17
17
*`DBG_VERBOSE` - most information
18
18
19
-
The desired debug level can be set via `setDebugLevel(DBG_WARNING)`.
19
+
The desired debug level can be set in code via `setDebugLevel(DBG_WARNING)` or while the code is running using the Serial Monitor.
20
20
21
21
Debug messages are written via `print` which supports `printf`-style formatted output.
22
22
@@ -34,8 +34,35 @@ If desired, timestamps can be prefixed to the debug message. Timestamp output ca
34
34
Normally all debug output is redirected to the primary serial output of each board (`Serial`). In case you want to redirect the output to another output stream you can make use of `setDebugOutputStream(&Serial2)`.
35
35
36
36
# Documentation
37
-
### Debug :
38
-
Arduino_DebugUtils Object that will be used for calling member functions.
37
+
## Code setup
38
+
39
+
### Include the Library
40
+
41
+
Include the Arduino_DebugUtils library by adding
42
+
```C++
43
+
#include "Arduino_DebugUtils.h"
44
+
```
45
+
at the top of your code.
46
+
47
+
### Setup the Serial Port
48
+
49
+
By default, the Output Stream and input port for printing debug messages and receiving config commands is `Serial`.
50
+
51
+
For minimal setup, just create the Serial object with a specified baud rate.
52
+
```C++
53
+
Serial.begin(9600); // Set baud rate here. Make sure you match the same baud rate in your terminal or monitor
54
+
```
55
+
In advanced cases you can use other serial ports (if available), or a Software Serial object. You can also (optionally) set a different Debug Level, turn on timestamps and debug labels.
56
+
57
+
```C++
58
+
mySerial.begin(9600); // Set baud rate here. Make sure you match the same baud rate in your terminal or monitor
59
+
Debug.setDebugOutputStream(&mySerial);
60
+
Debug.setDebugLevel(DBG_VERBOSE);
61
+
Debug.timestampOn();
62
+
```
63
+
64
+
### Debug: object
65
+
Arduino_DebugUtils Object that will be used for calling member functions is automatically instantiated when you include the library.
39
66
40
67
### Debug.setDebugLevel(int const debug_level) :
41
68
Parameter debug_level in order of lowest to highest priority are : `DBG_NONE`, `DBG_ERROR`, `DBG_WARNING`, `DBG_INFO` (default), `DBG_DEBUG`, and `DBG_VERBOSE`.
@@ -79,6 +106,28 @@ Debug.timestampOff();
79
106
DEBUG_VERBOSE("i = %d", i); //Output looks like : i = 21
80
107
```
81
108
109
+
### Debug.debugLabelOn() :
110
+
Calling this function switches on the Debug Label in the `Debug.print()` function call;
111
+
By default, printing the debug label is off, unless turned on using this function call.
112
+
113
+
Return type: void.
114
+
115
+
Example:
116
+
```C++
117
+
Debug.debugLabelOn();
118
+
```
119
+
120
+
### Debug.debugLabelOff() :
121
+
Calling this function switches off the Debug Label in the `Debug.print()` function call;
122
+
By default, printing the debug label is off, unless turned on using this function call.
123
+
124
+
Return type: void.
125
+
126
+
Example:
127
+
```C++
128
+
Debug.debugLabelOff();
129
+
```
130
+
82
131
### Debug.newlineOn() :
83
132
Calling this function ensures that a newline will be sent at the end of the `Debug.print()` function call;
This function prints the message if parameter `debug_level` in the `Debug.print(debug_level, ...)` function call belongs to the range: DBG_ERROR <= debug_level <= (<DBG_LEVEL> that has been set using `setDebugLevel()` function).
- toggle the display of the prefixed Timestamp at the beginning of the `Debug.print()` function call
167
+
- toggle the display of the debug label at the beginning of the `Debug.print()` function call
168
+
- toggle the sending of a newline at the end of the `Debug.print()` function call
169
+
170
+
### Setup
171
+
172
+
Modify your `loop()` function to call `Debug.processDebugConfigCommand()` each time.
173
+
174
+
Example:
175
+
```C++
176
+
int i = 0;
177
+
178
+
void loop() {
179
+
DEBUG_VERBOSE("i = %d", i);
180
+
i++;
181
+
Debug.processDebugConfigCommand();
182
+
delay(1000); // See note on timing below
183
+
}
184
+
```
185
+
186
+
### Timing
187
+
- If you have a delay in your `loop()` (as is the case with the example code) this will also delay action on any entered commands, so for faster response call `processDebugConfigCommand()` more often.
188
+
189
+
### Trouble-shooting
190
+
Check your monitor or terminal is configured:
191
+
- to send a LF or CRLF Line Ending at the end of a message sent via the serial port.
192
+
- to use the same baud rate specified when setting up the Serial object (9600 in the examples)
0 commit comments