Pages: [1]   Go Down
Author Topic: problem with loading when one more line is added to sketch  (Read 861 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Hi,

I have been writing a sketch that runs a small web server from the arduino uno.  This seems to work just great, except, without any warnings or other indications, the program seems to suffer from some sort of memory use issue during upload if I try to add in just one more line of code.  The overall program size is around 14K, out of a max of 32k.  The additional code should not be using up the limited SRAM, but maybe it is. 

In the program there are a number of lines that use client.print to serve up some HTML.  An example of them is shown below.  If I don't comment out any one of these four working lines of good code the program compiles, and then uploads, but rather than serving up the web page, it shoots fast jibberish out the serial monitor port back to the PC, rather than the expected network activity.  It doesn't matter which line is commented out. No errors when compiling, no errors when uploading.  That is the puzzle, which is leading me to think it is a memory issue, and since it is less than the flash available, its likely SRAM.  They all work fine provided that they are all not in the sketch at the same time. 

So, here are some simple questions,

1.  How do I figure out the memory utilization for the SRAM?  Is there a memory map file being stored some place?  Is there an assembly listing file available to aid in debug?

2.  Are the strings in the client.print, being stored in SRAM or are they being loaded from flash.  They are constants, so i would have expected the underlying code to use a pointer to the flash, however it is possible that it is storing these in SRAM, all at once, rather than bringing them one at at time when the line of code is actually being executed.

3.  If I am running out of SRAM, is there any easy way to find out?  The monitor goes out to lunch when I uncoment any of the additional lines.

4.  is there any way to direct the ARduino to force storage of constants in flash, so that the memory can be better managed, or at least understood?

5.  The program also uses an X10firecracker library and its associated lower level .h files, such as wiring.h (Not wire.h). 

Suggestions on how to resolve and debug this would be great.  A snipet of the issue is below.

Thank You,
Walt,

  client.println("<FORM METHOD='LINK' ACTION='http://192.168.1.177/XSomething_else\r'><INPUT TYPE='submit' VALUE='Turn on the light'></FORM>  ");
           client.println("<FORM METHOD='LINK' ACTION='http://192.168.1.177/Ytry_this_one\r'><INPUT TYPE='submit' VALUE='Light on dim it up down and Light off'></FORM>  ");
  //        client.println("<FORM METHOD='LINK' ACTION='http://192.168.1.177/Z\r'><INPUT TYPE='submit' VALUE='Light off'></FORM>  ");
       client.println("<FORM METHOD='LINK' ACTION='http://192.168.1.177/ZSomething_else\r'><INPUT TYPE='submit' VALUE='Turn off the light'></FORM>  ");   

Logged

Chile
Offline Offline
Edison Member
*
Karma: 32
Posts: 1233
Arduino rocks?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
3.  If I am running out of SRAM, is there any easy way to find out?  The monitor goes out to lunch when I uncoment any of the additional lines.

Check http://arduino.cc/forum/index.php/topic,118440.0.html
Logged

My website: http://ried.cl

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 19
Posts: 3114
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
is there any way to direct the ARduino to force storage of constants in flash, so that the memory can be better managed, or at least understood?

Try using the F() macro. It keeps character literals in flash.

Code:
  client.println(F("<FORM METHOD='LINK' ACTION='http://192.168.1.177/XSomething_else\r'><INPUT TYPE='submit' VALUE='Turn on the light'></FORM>  "));
           client.println(F("<FORM METHOD='LINK' ACTION='http://192.168.1.177/Ytry_this_one\r'><INPUT TYPE='submit' VALUE='Light on dim it up down and Light off'></FORM>  "));
  //        client.println(F("<FORM METHOD='LINK' ACTION='http://192.168.1.177/Z\r'><INPUT TYPE='submit' VALUE='Light off'></FORM>  "));
       client.println(F("<FORM METHOD='LINK' ACTION='http://192.168.1.177/ZSomething_else\r'><INPUT TYPE='submit' VALUE='Turn off the light'></FORM>  "));
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46240
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It might also be a lot easier to create one form with multiple buttons than to create multiple forms with one button each.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the F(...string/litteral...) answer which put this in flash.  That cleared up the problem  I have since looked at the documentation and can not find any reference to this.  Maybe I am missing out on some of the documentation.  Where would I have found this?

I will look into the HTML multiple forms/single forms, great suggestion..

Thank You,
Walt,
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 19
Posts: 3114
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Where would I have found this?

It's in the release notes for IDE 1.0+, and it's also mentioned on the Serial.print()/println() pages. As Ethernet print()/println() is derived from the same base as Serial, it works the same.
Logged

Offline Offline
Edison Member
*
Karma: 17
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Where would I have found this?

It's in the release notes for IDE 1.0+, and it's also mentioned on the Serial.print()/println() pages. As Ethernet print()/println() is derived from the same base as Serial, it works the same.

oh, Arduino...
-class Print has a method to use __FlashStringHelper and thus F(). No other arduino files and few external libraries do (They just derive from Print)
-The macro is defined in WString.h (Even though it has nothing to do with String)
-It is documented on the pages for exactly one class derived from Print.

No, this makes perfect sense.
Logged

Pages: [1]   Go Up
Jump to: