problem with loading when one more line is added to sketch

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(" ");
client.println(" ");
// client.println(" ");
client.println(" ");

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

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.

  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>  "));

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

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,

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.

dxw00d:

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.