DebugSerial.println()

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

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.

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

Ditch the macro. Write a function!

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 :slight_smile:
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.

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.

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...

This may help you:

/*
  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
}

LarryD:
This may help you:

/*

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
}

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?

Try this

@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.

Noted and Thanks.

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.

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

//***************************************************************

//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:

/*
  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"

.

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.

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://www.arduino.cc/en/Hacking/BuildProcess

.

@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?

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"

.

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?