# DebugSerial.println()

**URL:** <https://forum.arduino.cc/t/debugserial-println/330877>\
**Category:** Programming\
**Created:** [August 21, 2015, 8:23pm UTC](https://forum.arduino.cc/t/debugserial-println/330877 "2015-08-21T20:23:47Z")\
**Posts on this page:** 19\
**Page:** 2

<div class="post-metadata">

**Author:** ![Robin2](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/robin2/32/216045_2.png) [@Robin2](https://forum.arduino.cc/u/Robin2)\
**Post date:** [August 22, 2015, 4:58pm UTC](https://forum.arduino.cc/t/debugserial-println/330877/28 "2015-08-22T16:58:59Z")

</div>

> aisc:  
> @Robin2: I ran the code yesterday and from memory there was nothing special about the output in fact very l
> 
> ...SNIP...
> 
> If there is a DebugSerial.println() function how do I use it to achieve the same as the above code.

These lines from Reply #10 suggest that you did not understand what I wrote in Reply #9

I have no problem with "not understanding" as long as you say so and give me a chance to explain further. But proceeding blindly without understanding is just a silly waste of everyone's time.

And it sounds as if you want to use the DebugSerial but you did not answer my question "What do you want to achieve ?"

...R

---

<div class="post-metadata">

**Author:** ![aisc](https://avatars.discourse-cdn.com/v4/letter/a/b782af/32.png) [@aisc](https://forum.arduino.cc/u/aisc)\
**Post date:** [August 22, 2015, 5:05pm UTC](https://forum.arduino.cc/t/debugserial-println/330877/29 "2015-08-22T17:05:02Z")

</div>

> Delta\_G:  
> The F macro is just for constant strings as arguments to functions so they don't take up RAM. You can't use it on a variable like that. Just drop the F.

Hmmm... I can see now I am converting the constant string to a variable - I guess I have to rethink my function.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [August 22, 2015, 5:12pm UTC](https://forum.arduino.cc/t/debugserial-println/330877/30 "2015-08-22T17:12:34Z")

</div>

> The fix is probably in the error message - but above my head

Ditch the macro. Write a function!

---

<div class="post-metadata">

**Author:** ![aisc](https://avatars.discourse-cdn.com/v4/letter/a/b782af/32.png) [@aisc](https://forum.arduino.cc/u/aisc)\
**Post date:** [August 22, 2015, 5:18pm UTC](https://forum.arduino.cc/t/debugserial-println/330877/31 "2015-08-22T17:18:54Z")

</div>

> Robin2:  
> And it sounds as if you want to use the DebugSerial but you did not answer my question "What do you want to achieve ?"
> 
> ...R

hmmm... must the English language barrier again 🙂  
I did answer your question...  
In fact I gave you a detailed account of what I am doing and what I want to achieve in the form of the code I posted in post #10.

FWIW I do understand there is no "DebugSerial" as such - refer my post #12.

---

<div class="post-metadata">

**Author:** ![aisc](https://avatars.discourse-cdn.com/v4/letter/a/b782af/32.png) [@aisc](https://forum.arduino.cc/u/aisc)\
**Post date:** [August 22, 2015, 5:23pm UTC](https://forum.arduino.cc/t/debugserial-println/330877/32 "2015-08-22T17:23:07Z")

</div>

> AWOL:  
> If you drop the F, it goes in RAM.

Exactly, which is why I am trying NOT to drop the F.

> PaulS:  
> Ditch the macro. Write a function!

LOL - I did write a function :).  
I am just trying to take advantage of the benefits of the F() macro within the function when mode\_Debug is defined.  
If mode\_Debug is not defined I guess it is a moot point - I better test that theory.

---

<div class="post-metadata">

**Author:** ![aisc](https://avatars.discourse-cdn.com/v4/letter/a/b782af/32.png) [@aisc](https://forum.arduino.cc/u/aisc)\
**Post date:** [August 22, 2015, 5:56pm UTC](https://forum.arduino.cc/t/debugserial-println/330877/34 "2015-08-22T17:56:31Z")

</div>

> Delta\_G:  
> The key is that you use the F macro on the constant string when you call the function, not the function parameter in the definition.

I was trying to write a "one-size-fits-all" function for print, println, text constants and a variable.  
To use the F() macro when calling the function I think I will need to have multiple functions.  
Working on it...

---

<div class="post-metadata">

**Author:** ![LarryD](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/larryd/32/215550_2.png) [@LarryD](https://forum.arduino.cc/u/LarryD)\
**Post date:** [August 22, 2015, 7:52pm UTC](https://forum.arduino.cc/t/debugserial-println/330877/35 "2015-08-22T19:52:37Z")

</div>

This may help you:

```cpp
/*
  Blink
 Turns on an LED on for 1/2 a second, then off for 1/2 a second, repeatedly.
*/

// ***************************************************************
//If you comment the line:    #define DEBUG
//the DPRINT & DPRINTLN lines are defined as blank, thus would be ignored by the compiler
#define DEBUG  // if this line is NOT commented, these macros will be included in the sketch
//examples:
// DPRINTLN("Testing123");    
// DPRINTLN(0xC0FFEEul,DEC);
// DPRINTLN(12648430ul,HEX);
// DPRINTLNF("This message came from your flash");  

#ifdef DEBUG
#define DPRINT(...)    Serial.print( __VA_ARGS__ )
//OR, #define DPRINT(args...)    Serial.print(args)
#define DPRINTLN(...)  Serial.println( __VA_ARGS__ )
#define DRINTF(...)    Serial.print(F( __VA_ARGS__ ))
#define DPRINTLNF(...) Serial.println(F( __VA_ARGS__ )) //printing text using the F macro

#else
#define DPRINT(...)    //blank line
#define DPRINTLN(...)  //blank line
#define DPRINTF(...)    //blank line
#define DPRINTLNF(...)  //blank line

#endif
// ***************************************************************

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

int z = 123;

void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
  Serial.begin(9600);

}

void loop() {
  digitalWrite(led, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(500);              // wait for 1/2 a second
  digitalWrite(led, LOW);  // turn the LED off by making the voltage LOW
  delay(500);              // wait for 1/2 a second

  //the following 6 lines of code will be expanded only if the word "DEBUG" is defined
  //if "DEBUG" is not defined, the following 6 lines are ignored
  DPRINTLN("Testing123");
  DPRINTLN(0xC0FFEEul,DEC);  // print a hex number in decimal
  DPRINTLN(12648430ul,HEX);  // print a decimal number in hex
  DPRINTLNF("This message came from your flash ");  // this text is from your flash thus saving ram
  DPRINTLN( z ); // print the value of z
  DPRINTLN();    // print a blank line
}

```

---

<div class="post-metadata">

**Author:** ![aisc](https://avatars.discourse-cdn.com/v4/letter/a/b782af/32.png) [@aisc](https://forum.arduino.cc/u/aisc)\
**Post date:** [August 22, 2015, 9:07pm UTC](https://forum.arduino.cc/t/debugserial-println/330877/36 "2015-08-22T21:07:53Z")

</div>

> LarryD:  
> This may help you:
> 
> ```arduino
> /*
> 
> ```

Blink  
Turns on an LED on for 1/2 a second, then off for 1/2 a second, repeatedly.  
\*/

//\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
//If you comment the line:&nbsp; &nbsp; #define DEBUG  
//the DPRINT & DPRINTLN lines are defined as blank, thus would be ignored by the compiler  
#define DEBUG&nbsp; // if this line is NOT commented, these macros will be included in the sketch  
//examples:  
// DPRINTLN("Testing123");&nbsp; &nbsp;  
// DPRINTLN(0xC0FFEEul,DEC);  
// DPRINTLN(12648430ul,HEX);  
// DPRINTLNF("This message came from your flash");

#ifdef DEBUG  
#define DPRINT(...)&nbsp; &nbsp; Serial.print( **VA\_ARGS** )  
//OR, #define DPRINT(args...)&nbsp; &nbsp; Serial.print(args)  
#define DPRINTLN(...)&nbsp; Serial.println( **VA\_ARGS** )  
#define DRINTF(...)&nbsp; &nbsp; Serial.print(F( **VA\_ARGS** ))  
#define DPRINTLNF(...) Serial.println(F( **VA\_ARGS** )) //printing text using the F macro

#else  
#define DPRINT(...)&nbsp; &nbsp; //blank line  
#define DPRINTLN(...)&nbsp; //blank line  
#define DPRINTF(...)&nbsp; &nbsp; //blank line  
#define DPRINTLNF(...)&nbsp; //blank line

#endif  
//\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

// Pin 13 has an LED connected on most Arduino boards.  
// give it a name:  
int led = 13;

int z = 123;

void setup() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  
&nbsp; // initialize the digital pin as an output.  
&nbsp; pinMode(led, OUTPUT);&nbsp; &nbsp;  
&nbsp; Serial.begin(9600);

}

void loop() {  
&nbsp; digitalWrite(led, HIGH);&nbsp; // turn the LED on (HIGH is the voltage level)  
&nbsp; delay(500);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // wait for 1/2 a second  
&nbsp; digitalWrite(led, LOW);&nbsp; // turn the LED off by making the voltage LOW  
&nbsp; delay(500);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // wait for 1/2 a second

//the following 6 lines of code will be expanded only if the word "DEBUG" is defined  
&nbsp; //if "DEBUG" is not defined, the following 6 lines are ignored  
&nbsp; DPRINTLN("Testing123");  
&nbsp; DPRINTLN(0xC0FFEEul,DEC);&nbsp; // print a hex number in decimal  
&nbsp; DPRINTLN(12648430ul,HEX);&nbsp; // print a decimal number in hex  
&nbsp; DPRINTLNF("This message came from your flash ");&nbsp; // this text is from your flash thus saving ram  
&nbsp; DPRINTLN( z ); // print the value of z  
&nbsp; DPRINTLN();&nbsp; &nbsp; // print a blank line  
}

> ```arduino
> 
> ```

Ok this is virtually repeat post of your earlier post.  
When I read the earlier post I could not really follow it.  
Now it is starting to make a bit of sense to me, but I have some pretty dumb questions...

What is the significance of the following if any:

1. "..." in this : #define DPRINT(...)
2. "args..." in this : #define DPRINT(args...)
3. " **VA\_ARGS**" in this : Serial.print( **VA\_ARGS** )

Is it a standard format?

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [August 22, 2015, 9:10pm UTC](https://forum.arduino.cc/t/debugserial-println/330877/37 "2015-08-22T21:10:43Z")

</div>

Try [this](http://lmgtfy.com/?q= __VA_ARGS__ )

---

<div class="post-metadata">

**Author:** ![LarryD](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/larryd/32/215550_2.png) [@LarryD](https://forum.arduino.cc/u/LarryD)\
**Post date:** [August 22, 2015, 10:44pm UTC](https://forum.arduino.cc/t/debugserial-println/330877/38 "2015-08-22T22:44:36Z")

</div>

@AWOL's link explains it all.

DPRINTLN("Testing123");  
becomes  
Serial.println("Testing123");

DPRINTLN(0xC0FFEEul,DEC);  
becomes  
Serial.println(0xCOFFEE,DEC);

DPRINTLNF("This message came from your flash ");  
becomes  
Serial.println(F("This message came from your flash "));

etc.

This occurs only if DEBUG is defined, else these lines are not looked at by the compiler.

You can make your Marcos this way to handle the situations you need.

While you are debugging your code, make sure you have the line #define DEBUG in your code.  
When you are finished debugging, you remove the define line, resulting in the macros replaced as blank lines.

---

<div class="post-metadata">

**Author:** ![aisc](https://avatars.discourse-cdn.com/v4/letter/a/b782af/32.png) [@aisc](https://forum.arduino.cc/u/aisc)\
**Post date:** [August 23, 2015, 3:50am UTC](https://forum.arduino.cc/t/debugserial-println/330877/39 "2015-08-23T03:50:26Z")

</div>

Noted and Thanks.

---

<div class="post-metadata">

**Author:** ![aisc](https://avatars.discourse-cdn.com/v4/letter/a/b782af/32.png) [@aisc](https://forum.arduino.cc/u/aisc)\
**Post date:** [August 23, 2015, 5:21am UTC](https://forum.arduino.cc/t/debugserial-println/330877/40 "2015-08-23T05:21:22Z")

</div>

Thanks to all for your help.  
I have implemented "mode\_Debug" in my sketch based on the macro approach suggested by LarryD.

With minimal options enabled in the sketch, this is the result (running on a Mega) :

> +mode\_Debug  
> Sketch uses 21,148 bytes (8%) of program storage space. Maximum is 253,952 bytes.  
> Global variables use 1,616 bytes (19%) of dynamic memory, leaving 6,576 bytes for local variables. Maximum is 8,192 bytes.
> 
> -mode\_Debug  
> Sketch uses 19,688 bytes (7%) of program storage space. Maximum is 253,952 bytes.  
> Global variables use 1,620 bytes (19%) of dynamic memory, leaving 6,572 bytes for local variables. Maximum is 8,192 bytes.

---

<div class="post-metadata">

**Author:** ![LarryD](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/larryd/32/215550_2.png) [@LarryD](https://forum.arduino.cc/u/LarryD)\
**Post date:** [August 23, 2015, 10:37pm UTC](https://forum.arduino.cc/t/debugserial-println/330877/41 "2015-08-23T22:37:10Z")

</div>

Just a note:  
If you want, you can put debug macros in a .h file in your library folder so you can use them in other sketches.

C:\Users\YOUR NAME\Documents\Arduino\libraries\MyMarcos\MyMacros.h

```cpp
// ***************************************************************

//examples:
// DPRINTLN("Testing123");    
// DPRINTLN(0xC0FFEEul,DEC);
// DPRINTLN(12648430ul,HEX);
// DPRINTLNF("This message came from your flash");  

#ifdef DEBUG
#define DPRINT(...)    Serial.print( __VA_ARGS__ )
//OR, #define DPRINT(args...)    Serial.print(args)
#define DPRINTLN(...)  Serial.println( __VA_ARGS__ )
#define DRINTF(...)    Serial.print(F( __VA_ARGS__ ))
#define DPRINTLNF(...) Serial.println(F( __VA_ARGS__ )) //printing text using the F macro

#else
#define DPRINT(...)     //blank line
#define DPRINTLN(...)   //blank line
#define DPRINTF(...)    //blank line
#define DPRINTLNF(...)  //blank line

#endif
// ***************************************************************

```

Then use this .h file as seen below:

```cpp
/*
  Blink
 Turns on an LED on for 1/2 a second, then off for 1/2 a second, repeatedly.
*/

#define DEBUG // to enable the macros, this line is to proceed the next 
#include <MyMacros.h>

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

int z = 123;

void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
  Serial.begin(9600);

}

void loop() {
  digitalWrite(led, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(500);               // wait for 1/2 a second
  digitalWrite(led, LOW);   // turn the LED off by making the voltage LOW
  delay(500);               // wait for 1/2 a second

  //the following 6 lines of code will be expanded only if the word "DEBUG" is defined
  //if "DEBUG" is not defined, the following 6 lines are ignored
  DPRINTLN("Testing123");
  DPRINTLN(0xC0FFEEul,DEC);  // print a hex number in decimal
  DPRINTLN(12648430ul,HEX);  // print a decimal number in hex
  DPRINTLNF("This message came from your flash ");  // this text is from your flash thus saving ram
  DPRINTLN( z ); // print the value of z
  DPRINTLN();    // print a blank line
}

```

You can also make a new tab in your current directory and place your definitions there too.  
In this case you would then use:

#define DEBUG  
#include "MyMacros.h"

.

---

<div class="post-metadata">

**Author:** ![aisc](https://avatars.discourse-cdn.com/v4/letter/a/b782af/32.png) [@aisc](https://forum.arduino.cc/u/aisc)\
**Post date:** [August 24, 2015, 5:55am UTC](https://forum.arduino.cc/t/debugserial-println/330877/42 "2015-08-24T05:55:40Z")

</div>

> LarryD:  
> Just a note:  
> If you want, you can put debug macros in a .h file in your library folder so you can use them in other sketches.

Great idea - done!

> You can also make a new tab in your current directory and place your definitions there too.  
> In this case you would then use:
> 
> #define DEBUG  
> #include "MyMacros.h".

hmmmm... This method I want to experiment with - I have been trying to include libraries on an optional basis but no joy. By "tab" do u mean folder? FWIW I speak Windoze not Linux.

---

<div class="post-metadata">

**Author:** ![LarryD](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/larryd/32/215550_2.png) [@LarryD](https://forum.arduino.cc/u/LarryD)\
**Post date:** [August 24, 2015, 5:16pm UTC](https://forum.arduino.cc/t/debugserial-println/330877/43 "2015-08-24T17:16:00Z")

</div>

Tabs  
You can have multiple tabs in your sketches.  
You then put different sections of your sketch into these tabs.(macros, functions, etc)  
This is one way to keep common elements separated.  
See:

[![](https://europe1.discourse-cdn.com/arduino/original/4X/5/4/f/54f8ddc088777b17cc2e3613de75d0bb32d98aa3.jpeg "Arduino: The use of Tabs in the Arduino IDE") ](https://www.youtube.com/watch?v=dSAb3LZBHp0)

> **[Using tabs in Arduino IDE](https://liudr.wordpress.com/2011/02/16/using-tabs-in-arduino-ide/)**
>
> If you plan to write a moderate to long program in Arduino IDE, you should learn to use tabs to keep your codes organized. Let’s talk about this issue in some details. First, you should have …

[https://www.arduino.cc/en/Hacking/BuildProcess](https://www.arduino.cc/en/Hacking/BuildProcess)

.

---

<div class="post-metadata">

**Author:** ![aisc](https://avatars.discourse-cdn.com/v4/letter/a/b782af/32.png) [@aisc](https://forum.arduino.cc/u/aisc)\
**Post date:** [August 24, 2015, 6:45pm UTC](https://forum.arduino.cc/t/debugserial-println/330877/44 "2015-08-24T18:45:35Z")

</div>

@LarryD: Thanks for the links.  
My sketch is 700 lines long, so I will definitely be moving some code to tabs.

One question about positioning of functions.....  
When I was compiling, I had to move the functions to before setup or the sketch would not compile.  
Now understand if I moved the functions onto a tab with a .h extension then it should be ok, because it will compile first.

But if the functions were left in the main sketch file, is there a work-around to position the functions after the loop?

---

<div class="post-metadata">

**Author:** ![LarryD](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/larryd/32/215550_2.png) [@LarryD](https://forum.arduino.cc/u/LarryD)\
**Post date:** [August 24, 2015, 7:13pm UTC](https://forum.arduino.cc/t/debugserial-println/330877/45 "2015-08-24T19:13:24Z")

</div>

> When I was compiling, I had to move the functions to before setup or the sketch would not compile.

- I would have to see what you are talking about here.  
You may need a function prototype before setup().

- Functions can be placed at the end of a sketch or in a Tab.

- .h code in Tabs require this kind of formating:

#define DEBUG  
#include "MyMacros.h"

.

---

<div class="post-metadata">

**Author:** ![aisc](https://avatars.discourse-cdn.com/v4/letter/a/b782af/32.png) [@aisc](https://forum.arduino.cc/u/aisc)\
**Post date:** [August 25, 2015, 5:37am UTC](https://forum.arduino.cc/t/debugserial-println/330877/46 "2015-08-25T05:37:29Z")

</div>

> LarryD:
> 
> - I would have to see what you are talking about here.  
> You may need a function prototype before setup().

Tried Googling for info on function prototype, but so far found nothing related to the issue.  
I tried moving all the functions to the bottom and this time the compiler did not complain - weird.  
So let's drop this for now since the problem seems to have gone away

Anyway my sketch now has several .h tabs making editing much easier.

Very briefly, when would I give a tab a .c or a .cpp extension?

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 9:26pm UTC](https://forum.arduino.cc/t/debugserial-println/330877/47 "2021-05-05T21:26:45Z")

</div>

Closed on May 5, 2021, 9:26pm UTC



[Previous page](https://forum.arduino.cc/t/debugserial-println/330877.md?page=1)
