Go Down

Topic: DS1307 Real time clock Datalogger (Read 2 times) previous topic - next topic

peko86

I partially solved the problem using UNIX time, but now, the delay is being existing yet :smiley-sad-blue:  Anyone knows how to store the time with precission (using more variables or something like this)??? I tried a lot of methods, but the best option is the next....(I must to repeat that I don´t copy all code, because it has 1500 lines of length. But if you need it, I´ll post  it. Thank you to everyone


Quote

          DateTime now = RTC.now();   //Para obtener el tiempo unix
          unsigned long currentTime = now.unixtime();//Obtiene el tiempo UNIX para el tiempo de refresco unicamente
              if (currentTime -lastReadTime >=  refresh_rate) {
                 
              File logFile = SD.open("LOG.txt", O_CREAT | O_WRITE);//O_CREAT | O_WRITE puede cambiarse por FILE_WRITE
              
              lastReadTime = currentTime;
              
                       logFile.print(monthDay);
                       logFile.print("/");
                       logFile.print(month);
                       logFile.print("/");
                       logFile.print(year);
                       
                       logFile.print("  -  ");
                       
                       logFile.print(hour);
                       logFile.print(":");
                       logFile.print(minute);
                       logFile.print(":");
                       logFile.print(second);
                       
                       logFile.print(",");//Separador de columna
              
                      for (int l=0; l<numSensoresT; l++)
                          {
                            logFile.print(temparray[l]);
                               if (l < numSensoresT-1)
                                  {
                                  logFile.print(",");
                                  }
                               else
                                  {
                                    logFile.println();
                                    
                                  }
                          }
              
              logFile.close();
                                                   
              
              }                                  


pylon

Can you describe what your problem is?

Your code logs the sensor values every refresh_rate seconds. What do you expect it to do?

peko86

At first, thank you for your fast answer pylon....My problem is the precission: When I put a refresh time It takes samples good and makes a timestamp that seems good, but when it has 30-150 samples (it depends, and its aleatory-I think), the timestamp goes 1 second after, as I describe in my first post, for example if the sample rate is 30 seconds and begins in second 00: the routine is 00 30 00 30 00 [....]30  00  31. It may be a solution for this (this is an end of studies project, for the university, and I wish to do it perfect). Thank you :)

pylon

If this is still the case even for the code above, your problem is in the main code not in the posted part of it. Meaning you have to post the full code to enable us to find the bug.

My guess is that your main loop is run only once a second. Then this kind of time slip is possible and probable after some time.

peko86

First of all....Thank you very much for your answer pylon...I´ll post the code now....But before this, I must to explain  various things of my code (for best understanding):

-The first thing is that I´m relatively newbie in this kind of programming languaje, and Im sure that you will see a lot of bugs of other parts of the program.
-This project is a part of my end studies project (Naval Engineering), this instrument will log temperatures, air flows and other parameters to study the efficiency of a marine instalation (i´ll do some studies too-when I finish this instrument)
-This instrument-At the moment has programmed a Nokia 5110LCD, a keypad (for configure parameters, and configurations like number of sensors or the date or time in the DS1307 RTC, an SD card to save data, and temperature sensors DS18B20).
-The menus (and there are a lot) are incompleted, only run the things I have configured at the moment.
-the code is messy, so I order it when finished all.
-This is an example what I got in an excel:

Fecha y hora              T1   T2   T3   T4   T5
21/11/12  -  5:37:3   18.12   18.31   18.50   18.19   18.19
21/11/12  -  5:52:3   18.31   18.56   18.69   18.44   18.50
21/11/12  -  6:7:3   18.19   18.50   18.62   18.44   18.37
21/11/12  -  6:22:3   18.19   18.44   18.56   18.31   18.31
21/11/12  -  6:37:3   18.12   18.31   18.50   18.31   18.25
21/11/12  -  6:52:3   18.06   18.31   18.44   18.25   18.25
21/11/12  -  7:7:3   18.00   18.25   18.44   18.19   18.19
21/11/12  -  7:22:4   18.06   18.31   18.37   18.19   18.19
21/11/12  -  7:37:4   18.00   18.25   18.31   18.12   18.12
21/11/12  -  7:52:4   18.00   18.19   18.31   18.12   18.12
21/11/12  -  8:7:4   17.94   18.19   18.31   18.12   18.06
21/11/12  -  8:22:4   17.87   18.19   18.25   18.06   18.06
21/11/12  -  8:37:5   17.94   18.12   18.25   18.06   18.06
21/11/12  -  8:52:5   17.87   18.06   18.25   18.06   18.00
21/11/12  -  9:7:5   17.87   18.12   18.19   18.00   18.00
21/11/12  -  9:22:5   17.87   18.06   18.19   18.00   17.94
21/11/12  -  9:37:5   17.81   18.06   18.19   17.94   17.94
21/11/12  -  9:52:5   17.81   18.06   18.12   18.00   17.94
21/11/12  -  10:7:5   17.81   18.00   18.12   17.94   17.94
21/11/12  -  10:22:5   17.81   18.00   18.12   17.94   17.94
21/11/12  -  10:37:5   17.75   18.00   18.12   17.94   17.87
21/11/12  -  10:52:5   17.75   18.00   18.06   17.94   17.87
21/11/12  -  11:7:6   17.75   17.94   18.06   17.94   17.87
21/11/12  -  11:22:6   17.75   17.94   18.06   17.87   17.87
21/11/12  -  11:37:6   17.69   17.94   18.06   17.87   17.87
21/11/12  -  11:52:6   17.69   17.94   18.06   17.87   17.87
21/11/12  -  12:7:6   17.69   17.94   18.00   17.87   17.81
21/11/12  -  12:22:7   17.69   17.94   18.00   17.87   17.81
21/11/12  -  12:37:7   17.69   17.87   18.00   17.81   17.81
21/11/12  -  12:52:7   17.62   17.94   18.00   17.81   17.81
21/11/12  -  13:7:7   17.69   17.87   18.00   17.81   17.81
21/11/12  -  13:22:7   17.62   17.87   18.00   17.81   17.81
21/11/12  -  13:37:7   17.37   17.56   17.62   17.44   17.44
21/11/12  -  13:52:7   17.31   17.50   17.56   17.44   17.44
21/11/12  -  14:7:7   17.50   17.75   17.87   17.69   17.69
21/11/12  -  14:22:7   17.62   17.87   18.00   17.81   17.81
21/11/12  -  14:37:7   17.62   17.87   18.00   17.81   17.81

At the next post I´ll put the code.


Go Up