Go Down

Topic: sd.open returns '0' ? (Read 2299 times) previous topic - next topic



im currently messing arround with the SD library.

The micro SD card (2 GB) is connected to the Arduino Ethernet Shield. It initializes successfully but i cant read the content of my file:

Code: [Select]
else if (request.substring (0, 6) == "/test/")
              File fh = SD.open ("/test.txt");
              client.print (fh);
              client.print (fh.available());
              while (fh.available())
                client.print (fh.read());
              client.print ("END");



The file exists and contains 'HELLO WORLD !". I also tried it with filepath "test.txt"


SD.open() will also fail if you run out of SRAM. I see you are using some network device that uses a client.print() call. You should post your entire sketch.


Well, the whole sketch is kind of big, jsut a collection of multiple things



I didn't count every byte, but if that is an Uno, I suspect you are running out of SRAM. You might be able to eliminate some SRAM usage by using the F() function on those static strings.

This function works for me to check SRAM remaining. This is how to use it. If you run out of SRAM, it does not show zero. It shows a negative number or a very large number.
Code: [Select]
int freeRam() {
  extern int __heap_start,*__brkval;
  int v;
  return (int)&v - (__brkval == 0 ? (int)&__heap_start : (int) __brkval); 

void setup() {
  // all your setup stuff, then

  Serial.print(F("SRAM = "));


May 08, 2013, 06:29 pm Last Edit: May 08, 2013, 06:35 pm by ixde Reason: 1
Okay, ill try it later. Thank you.

What does the SRAM actually do (when does it get full?)

Also, how can i prevent it from getting full?


SRAM is data memory. The memory reported after a compile is program memory only. They are separate. An Uno has 2K SRAM. A Mega has 8K SRAM.

You can save SRAM (data memory) by keeping static strings in program memory instead of copying to SRAM. That is what the F() function does. You can see how to use it in the freeRam example above.


May 08, 2013, 08:08 pm Last Edit: May 08, 2013, 08:36 pm by ixde Reason: 1
Works fine. thank you.

Go Up