Pages: [1]   Go Down
Author Topic: Datalogger - lack of RAM?  (Read 896 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Edison Member
*
Karma: 57
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Edison Member
*
Karma: 31
Posts: 1417
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Where are the Nick Gammons of yesteryear?

Dee Why NSW
Offline Offline
Edison Member
*
Karma: 30
Posts: 1670
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

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();
}
Logged

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

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:

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! smiley-wink
Thanks a lot for good lesson, your code is working perfectly!
Logged

Huntsville,al USA
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Dee Why NSW
Offline Offline
Edison Member
*
Karma: 30
Posts: 1670
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Edison Member
*
Karma: 31
Posts: 1417
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Where are the Nick Gammons of yesteryear?

Miramar Beach, Florida
Online Online
Faraday Member
**
Karma: 115
Posts: 5370
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: