Go Down

Topic: Datalogger - lack of RAM? (Read 1 time) previous topic - next topic

paavo91

Hi.
I want to log temperatures to file .  File name must be in ddmmyy.txt format.

I made some code but my uC hang up when have to open file and save measures.

Below piece of code :

Code: [Select]
  if(flaga==1) {


  String nazwapliku = String(String(d) + String(ms) + String(rok_) +".txt" );
  char __nazwapliku[sizeof(nazwapliku)];
  nazwapliku.toCharArray(__nazwapliku, sizeof(__nazwapliku));



                plik=SD.open(__nazwapliku,FILE_WRITE); //otwieram plik do zapisu

                   if(plik) { //sprawdzam czy poprawnie otwarty
             
                              plik.print(now.year(), DEC);
                              plik.print("-");
                              plik.print(now.month(), DEC);
                              plik.print("-");
                              plik.print(now.day(), DEC);
                              plik.print(";");
                              plik.print(now.hour(), DEC);
                              plik.print(":");
                              plik.print(now.minute(), DEC);
                              plik.print(":");
                              if((now.second()) < 10)plik.print("0");
                              plik.print(now.second(),DEC);
                              plik.print(" ");
                              plik.print("T1=");
                              plik.print(calkowita);
                              plik.print(".");
                              plik.print(ulamek);
                              plik.print(" ");
                              plik.print("T2=");
                             
                              plik.print(calkowita2);
                              plik.print(".");
                              plik.println(ulamek2);


                             
                              plik.close(); //zamykam plik
                              flaga=0;
       
                            }

            }



I don't know what I am doing wrong , any suggestions?
thx

Erdin

Write the filename to the serial monitor, so you know what filename will be used. The filename must be in 8.3 format. That is the old FAT format for filenames.
If the filename is longer, it is not accepted.

el_supremo

You probably are running into a problem with lack of ram.
It is not a good idea to use the String class at all because it tends to use a lot of ram. Get rid of it completely - use character arrays/strings instead.

Pete

You are essentially doing the same as me, and your code looks like a date-as-filename snippet. I guess yoiur only problem is falling into the string trap. Here is a working version.
Code: [Select]


RTC_DS1307 RTC;
char filename[] = "00000000.CSV";
File myFile;

void loop()
{

getFileName();
createFileName();
delay(3000);
}

void getFileName(){

DateTime now = RTC.now();

filename[0] = (now.year()/1000)%10 + '0'; //To get 1st digit from year()
filename[1] = (now.year()/100)%10 + '0'; //To get 2nd digit from year()
filename[2] = (now.year()/10)%10 + '0'; //To get 3rd digit from year()
filename[3] = now.year()%10 + '0'; //To get 4th digit from year()
filename[4] = now.month()/10 + '0'; //To get 1st digit from month()
filename[5] = now.month()%10 + '0'; //To get 2nd digit from month()
filename[6] = now.day()/10 + '0'; //To get 1st digit from day()
filename[7] = now.day()%10 + '0'; //To get 2nd digit from day()

}

void createFileName(){
myFile = SD.open(filename, FILE_WRITE);
myFile.close();
}

paavo91


You are essentially doing the same as me, and your code looks like a date-as-filename snippet. I guess yoiur only problem is falling into the string trap. Here is a working version.
Code: [Select]


RTC_DS1307 RTC;
char filename[] = "00000000.CSV";
File myFile;

void loop()
{

getFileName();
createFileName();
delay(3000);
}

void getFileName(){

DateTime now = RTC.now();

filename[0] = (now.year()/1000)%10 + '0'; //To get 1st digit from year()
filename[1] = (now.year()/100)%10 + '0'; //To get 2nd digit from year()
filename[2] = (now.year()/10)%10 + '0'; //To get 3rd digit from year()
filename[3] = now.year()%10 + '0'; //To get 4th digit from year()
filename[4] = now.month()/10 + '0'; //To get 1st digit from month()
filename[5] = now.month()%10 + '0'; //To get 2nd digit from month()
filename[6] = now.day()/10 + '0'; //To get 1st digit from day()
filename[7] = now.day()%10 + '0'; //To get 2nd digit from day()

}

void createFileName(){
myFile = SD.open(filename, FILE_WRITE);
myFile.close();
}



Nick you made my day! ;)
Thanks a lot for good lesson, your code is working perfectly!

jsallas

I have had similar problems and traced it to the lack of memory. The UNO has only 2k so in researching the problem, I discovered that the SD library uses over 600 bytes, SoftwareSerial uses about 100 bytes, and the SD requires another 392 locations to perform the list files example.

You are looking in the wrong place. The Uno has about 32k of memory for your programmes and the data in question is simply passed through to the SD card anyway. The size of the programme is shown at the bottom of the window when you compile it. The Uno may not actually be the best choice for data logging, but data storage is usually the least of its problems.

el_supremo

Quote
The size of the programme is shown at the bottom of the window when you compile it

The IDE only shows how much flash ram the program uses. It does not show the amount of sram that's used and there's only 2kB in 328-based Arduinos.

Pete

SurferTim

I agree with el_supremo and the String variable type. Here is a post that had the same problem and a fix.
http://arduino.cc/forum/index.php/topic,151849.msg1144214.html#msg1144214

Go Up