Pages: [1]   Go Down
Author Topic: sd.open returns '0' ?  (Read 868 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey,

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:
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());
               
              fh.close();
              client.print ("END");
            }

Output:

00END

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

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 147
Posts: 6040
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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

http://pastebin.com/hPueAMTu
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 147
Posts: 6040
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
int freeRam() {
  extern int __heap_start,*__brkval;
  int v;
  return (int)&v - (__brkval == 0 ? (int)&__heap_start : (int) __brkval); 
}

void setup() {
  Serial.begin(9600);
  // all your setup stuff, then

  Serial.print(F("SRAM = "));
  Serial.println(freeRam());
}
Logged

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

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?
« Last Edit: May 08, 2013, 11:35:34 am by ixde » Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 147
Posts: 6040
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Works fine. thank you.
« Last Edit: May 08, 2013, 01:36:09 pm by ixde » Logged

Pages: [1]   Go Up
Jump to: