Go Down

Topic: Can SD Card be used to store ip address/MAC configs? (Read 4 times) previous topic - next topic


Oct 31, 2012, 01:13 pm Last Edit: Oct 31, 2012, 01:31 pm by SurferTim Reason: 1
The reported size by the compiler is the program memory, not SRAM. The Uno has only 2K, and the Mega has 8K. The SD.open() function requires a 500 byte buffer, even if the file is only 20 bytes. That is a quarter of your SRAM to open that file.

There is a MemoryFree library function in the playground.

edit:I think I used the one from github.

If you have questions about that, fat16lib hangs around the "Storage" section of the forum. He is the guy to ask.


I'm using an Uno.  I'm only trying to open the one file, "params.txt" or as in the later method, "Network.txt".  Neither is more than 1k. 

How can I tell how much SRAM I am using.  Is it the 'file' size reported at the load to the Uno from IDE?


Oct 30, 2012, 02:36 pm Last Edit: Oct 30, 2012, 03:01 pm by SurferTim Reason: 1
While both yours and mine work 'stand alone'  as soon as I try to merge either one with my sketch which calls up some Telnet configurations, the SD Card read fails.

Are you using an Uno or a Mega? You may be running out of SRAM when you merge the sketches with that telnet code.

edit: According to fat16lib, you can open as many SD files as you want now, but at the cost of 500 bytes SRAM per open file.


This looks good.  While both yours and mine work 'stand alone'  as soon as I try to merge either one with my sketch which calls up some Telnet configurations, the SD Card read fails.  I 'fooled' around with different sketchs, but I'm having little to no progress with any of them.  I'm not the type of guy that quits, but I think I'll investigate the suggestion earlier on in this thread to set the variables in EEPROM.  Eventually I'll make this work, but I have to move on.



Oct 29, 2012, 09:48 pm Last Edit: Oct 29, 2012, 10:05 pm by SurferTim Reason: 1
Why don't you store all the network settings? I used this for the contents of a file named "network.txt". The mac must be the first line, followed by ip, netmask, gateway, and dns in that order. Each on their own line.
Code: [Select]

Then I used this sketch:
Code: [Select]
#include <SD.h>
#include <SPI.h>
#include <Ethernet.h>

byte myMac[6];
byte myIP[4];
byte myNM[4];
byte myGW[4];
byte myDNS[4];

void setup() {


 if(!SD.begin(4)) Serial.println("SD fail");
 else Serial.println("SD ok");

 File fh = SD.open("network.txt",FILE_READ);
 char netBuffer[32];
   Serial.println("SD open fail");

 int chPos = 0;
 int lineNo = 0;
   char ch = fh.read();
   if(ch == '\r') {
     chPos = 0;

     switch(lineNo) {
       case 0:
//          Serial.print("mac ");        

       case 1:
//          Serial.print("ip ");        

       case 2:
//          Serial.print("netmask ");        

       case 3:
//          Serial.print("gateway ");        

       case 4:
//          Serial.print("dns ");        

//      Serial.println(netBuffer);
   else if(ch == '\n') {
      // do nothing
   else if(chPos < 31) {
     netBuffer[chPos] = ch;
     netBuffer[chPos] = 0;

 int x;
 Serial.print("\r\nmac ");
 for(x=0;x<6;x++) {
   if(x<5) Serial.print(":");

 Serial.print("\r\nip ");
 for(x=0;x<4;x++) {
   if(x<3) Serial.print(".");

 Serial.print("\r\nnetmask ");
 for(x=0;x<4;x++) {
   if(x<3) Serial.print(".");

 Serial.print("\r\ngateway ");
 for(x=0;x<4;x++) {
   if(x<3) Serial.print(".");

 Serial.print("\r\ndns ");
 for(x=0;x<4;x++) {
   if(x<3) Serial.print(".");

 Serial.println("\r\nStarting ethernet");

void loop() {

I commented out some of the serial debugging stuff. You can use it to debug your text file.

edit: Removed the double post. My bad.

Go Up