Go Down

Topic: Is there a limit of amount of Serial.print("")? (Read 1 time) previous topic - next topic

pierrot10

Dear All,

I am a beginner and I am experiencing a strange problem.
I ma using Serial.print("Debug") to debug and follow the step of the code.

For now I am testing that function.
Code: [Select]

static void sendData(const char* data) {

// digitalWrite(LED_STATUS, HIGH);
  Serial.print("");
  Serial.println("    *** Starting Sending ***");

  Serial.println("    > Setting up PDP Context");
  //sendATCommand("AT+CGDCONT=1,\"IP\",\"wap.cingular\"");
   
  Serial.println("    > Configure APN");
  //sendATCommand("AT+CGPCO=0,\"\",\"\", 1");
 
  Serial.println("    > Activate PDP Context");
  //sendATCommand("AT+CGACT=1,1");
 
  // Change 0.0.0.0 to reflect the server you want to connect to
  Serial.println("    > Configuring TCP connection to server");
  //sendATCommand("AT+SDATACONF=1,\"TCP\",\"92.104.69.134\",81");


  Serial.println("    > Starting TCP Connection");
  //sendATCommand("AT+SDATASTART=1,1");
 

  Serial.println("    > Delay of 1 sec");
  delay(1000);
 
  //Serial.println("Getting status");
  //sendATCommand("AT+SDATASTATUS=1");
 
  Serial.println("    > Sending data");
  //sendATCommand(data);
 
  //Serial.println("Getting status");
  //sendATCommand("AT+SDATASTATUS=1");
 
  // IThe problem startes here
  //Serial.println("    > Colse connectrion");
  //sendATCommand("AT+SDATASTART=1,0");
 
  // Serial.println("    > Disable PDP Context");
  //sendATCommand("AT+CGACT=0,1");
 
  // Clear string and flash LED
  //myStr.begin();
  //successLED();
 
  //digitalWrite(LED_STATUS, LOW);


All uncommented Serial.print() return the text and the code continue. Excpeted when I uncomment
Code: [Select]
Serial.println("    > Colse connectrion");
Just after the comment 
Quote
// IThe problem startes here.


Is there an error message? No. When I compile and send the code to the Ardiuno, it only display the letter
Quote
P

from "Power on" of the settup loop
Code: [Select]

void setup() {
   
  pinMode(LED_STATUS, OUTPUT); //int LED_STATUS = 13;
  pinMode(LED_ERROR, OUTPUT); // int LED_ERROR = 12;
  pinMode(GPS_RELAY, OUTPUT); // int GPS_RELAY = 9;
 
  ////Initialize serial ports for communication.
  Serial.begin(4800);
  cell.begin(9600);
 
  //Let's get started!
  Serial.println("Power on");
  // Check LEDS
  blinkLed(LED_ERROR, 5, 25);
  blinkLed(LED_STATUS, 5, 25); // Pin, flashtime, delay
}


Then I am a bit suprise.
(There is other Serial.print() in the code....)

Any idea?

Thank
Il ne suffit pas de tout savoir, la persévérance, c'est déjà presque tout!

AWOL

Sounds like you're running short of RAM.
Try changing your constant prints to the following format
Code: [Select]
Serial.println(F("    *** Starting Sending ***"));
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

pierrot10

Dear AWOL
Thank for your answer.
I am going to try it.
But what do you means by RAM. Can we increase the RAM of the arduino?
Should I limit the use of Serial.print()?
It true I use it a lot, but it only for debuging.
Il ne suffit pas de tout savoir, la persévérance, c'est déjà presque tout!

AWOL

Quote
But what do you means by RAM. Can we increase the RAM of the arduino?

RAM is read/write memory. It is very limited in size, and you can't (easily) add more.

Quote
Should I limit the use of Serial.print()?

Yes, debug prints should convey just enough information to tell you where you are and what you're doing, but no more.
Abbreviations are encouraged, verbosity, excess spaces and formatting (e.g."***") are deprecated.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

pierrot10

Ok, thenak for your answer.
I have a last question.
What is taken in considaration, the number of Serial.print() or the content of the Serial.print()

If I worte
Serial.print("Bla bla bla bla bla bla")

and I change to
Serial.print("bla"), does it will help?

For now the number of Serial.print() are suefull for me and I would like to avoid elimating it, but if I have I will.
(I could not test for now, but I will later)

Thnak for your support
Cheers and have a nice day
Il ne suffit pas de tout savoir, la persévérance, c'est déjà presque tout!

AWOL

Quote
What is taken in considaration, the number of Serial.print() or the content of the Serial.print()

The amount you print is what uses up RAM.
So,
Code: [Select]
Serial.print ("The quick brown fox"); will use 20 bytes of RAM
Every call to Serial.print will use up some program memory to set up the call and the parameter, but you have much more of this than RAM.
If you use the "F()" macro I showed above, then the compiler will leave the strings in program memory.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

pierrot10

Dear AWOL,

Thank for your answers. It helps.

There is a debug mode like Firebug does?
(May be it's not comparable....)
Sorry if my question are simple. I just start with Arduino

Yes I will use F, I understand now what does it do.

Cheers
Il ne suffit pas de tout savoir, la persévérance, c'est déjà presque tout!

pierrot10

I just found that code, to test the free Ram.

May be it can be useful

Code: [Select]

int freeRam ()
{
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}


Take care
Il ne suffit pas de tout savoir, la persévérance, c'est déjà presque tout!

pierrot10

Ok it's works but I got some issue...  :)

I would like to do the same with a variable

for exemple, when I do it
Code: [Select]
Serial.print(F("toto"));

it print toto

but when I want to print a buffer
Code: [Select]

char buffer ="data";
Serial.print(F(buffer));


When I compile it, I got a error of compilation " initializer fails to determine of '_c' "

Do you know why?
Il ne suffit pas de tout savoir, la persévérance, c'est déjà presque tout!

AWOL

Because you can't put a variable in program memory.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

wildbill

The F macro allows you to store constant strings in progmem and use them in routines such as serial print without consuming ram. Your buffer variable is stored in sram and is thus not eligible.

pierrot10

Il ne suffit pas de tout savoir, la persévérance, c'est déjà presque tout!

PeterH


Code: [Select]

char buffer ="data";



Does that compile? You seem to be initialising a char with a pointer, and a pointer doesn't fit in a char.
I only provide help via the forum - please do not contact me for private consultancy.

Go Up