I have quite a big Arduino project (in eclipse) going on with a lot of debug messages using the Serial.print("some string text") commands so that I can debug along the way.
One thing that I have noticed is that I reach a limit for how many of these I can have in the project. If i put too many, the program halts at very strange places. Ie: often long before my newest addition of a print command is supposed to execute.
My project .hex file is around 20k at the moment. The Arduino Uno limits around 30kb right? So it should not be too big.
So I feel that the actual problem is probably that maybe these serial commands are filling up my sram. Which is just 2kb. I am using a lot of libraries.
Is the command Serial.print("some string text") occupying SRAM? Surely gcc puts these string cnstants are in program space? but maybe they are not?
Or is it something else? I have an alternative theory that there is a serial.print buffer somewhere, and I am probably just filling it up with too many messages.
Description. Prints data to the serial port as human-readable ASCII text. This command can take many forms. Numbers are printed using an ASCII character for each digit. Floats are similarly printed as ASCII digits, defaulting to two decimal places.
The serial. print ( ) in Arduino prints the data to the serial port. The printed data is stored in the ASCII (American Standard Code for Information Interchange) format, which is a human-readable text. Each digit of a number is printed using the ASCII characters.
Yes it get's stored in RAM by default. You can use the solution by @Marty.
Serial. print() prints only the number or string, and Serial. println() prints it with a newline character.
Yup, string are stored in RAM by default. Although they're in the Flash memory too, but they're loaded into RAM when the Arduino boots.
However, if you use The Arduino IDE version 1.0 or later you can tell the compiler to read strings directly from Flash and not to bother loading them into RAM with the F()
macro:
Serial.Println(F("This string is read from Flash!"));
This will save RAM which is a good thing as there's much less RAM than Flash. See here for more details: * http://www.arduino.cc/playground/Main/Printf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With