Pages: [1]   Go Down
Author Topic: Is there a limit of amount of Serial.print("")?  (Read 955 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Sr. Member
****
Karma: 0
Posts: 399
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26328
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sounds like you're running short of RAM.
Try changing your constant prints to the following format
Code:
Serial.println(F("    *** Starting Sending ***"));
Logged

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

Offline Offline
Sr. Member
****
Karma: 0
Posts: 399
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26328
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Offline Offline
Sr. Member
****
Karma: 0
Posts: 399
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26328
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Offline Offline
Sr. Member
****
Karma: 0
Posts: 399
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

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

Offline Offline
Sr. Member
****
Karma: 0
Posts: 399
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

May be it can be useful

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

Take care
Logged

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

Offline Offline
Sr. Member
****
Karma: 0
Posts: 399
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok it's works but I got some issue...  smiley

I would like to do the same with a variable

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

it print toto

but when I want to print a buffer
Code:
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?
Logged

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26328
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Because you can't put a variable in program memory.
Logged

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

New Jersey
Online Online
Faraday Member
**
Karma: 67
Posts: 3700
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Sr. Member
****
Karma: 0
Posts: 399
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, thank for your answer
Logged

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

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Pages: [1]   Go Up
Jump to: