Hi
I wonder if that is a mistake to leave constructions such as "Serial.println("something");" in code without "Serial.begin(9600);" ?
Contoller will work normally and just skip that or stuck on it?
As far as I know, you have to initialize the Serial to see anything printed to it.
Why are you asking if you can do without Serial.begin (i.e. what's the issue you're having?)
No, I dont want to use Serial communication, just dont want to comment all Serial constructions in code.
Freeborn_rus:
No, I dont want to use Serial communication, just dont want to comment all Serial constructions in code.
Ah - well, I am just learning myself, but I don't see why you couldn't just comment out/delete the "Serial.begin();" line and leave the rest....assuming it compiles without Serial.begin().
It will compile with Serial.begin() commented out, but I would surmise the other Serial.xxx lines will still end up in the code inside the Arduino. So if memory is an issue, as it sometimes is, it would be prudent to zap those lines too.
JimboZA:
It will compile with Serial.begin() commented out, but I would surmise the other Serial.xxx lines will still end up in the code inside the Arduino. So if memory is an issue, as it sometimes is, it would be prudent to zap those lines too.
Quick question - when you comment out lines, do they get loaded into the Arduino, or does the compiler effectively "skip" those? In other words, if I comment out 1,000 lines, do those get loaded into the Arduino, taking up space?
If they don't take up any space, then OP could just Find/Replace all "Serial." with "//Serial." for easier removal of the Serial.print lines.
Comments don't end up in the Arduino, no.
You could verify that.... take a biggish sketch, compile it and make a note of the sketch size at the bottom of the IDE. Then /* ... */ most of it out (make sure it's still legal and it compiles), and note the size of that sketch.
I just for example commented a 5k sketch down to 500 bytes.
JimboZA:
Comments don't end up in the Arduino, no.You could verify that.... take a biggish sketch, compile it and make a note of the sketch size at the bottom of the IDE. Then /* ... */ most of it out (make sure it's still legal and it compiles), and note the size of that sketch.
I just for example commented a 5k sketch down to 500 bytes.
Thanks for the info! ![]()
What you can do with your serial prints is have them enabled for debugging but become no-ops at other times. This is illustrated in this post:
You would need to change your Serial.print (and Serial.println) to something else, but you could easily do that with a "change all" in the editor.
Or, here's an simpler example. Add this code to the near the beginning of your sketch:
class nullWriter : public Print
{
public:
virtual size_t write (const byte c) {}
void begin (const int baud) {}
};
nullWriter doNothing;
#define Serial doNothing
This gives you a doNothing replacement for Serial which does, well, nothing.
The #define changes references to Serial to doNothing.
Then it should compile OK, and your serial prints, effectively generate no code.
For example, doing that to the AsciiTable sketch, changes the size (for a Uno) from:
Binary sketch size: 2738 bytes (of a 32256 byte maximum)
to:
Binary sketch size: 1552 bytes (of a 32256 byte maximum)
To go back to seeing your output, just comment-out the #define line.