0

ADAFRUIT SD DATALOGGER WITH RTC Problem
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

ADAFRUIT SD DATALOGGER WITH RTC Problem

by yusjaa5569 on Tue Jan 06, 2015 7:33 pm

I made a rain tipper recorder with Adafruit SD Datalogger with RTC. My data logger stamping time and rain tipper logged data correctly only when i hook on with a serial port. When i remove the serial. it olny capture as followings data into my SD card, as if the clock no longer ticking...
Date Time RainAccum(ml)
1363131985 2165/165/165 165:165:85" 0
1363131985 2165/165/165 165:165:85" 0
1363131985 2165/165/165 165:165:85" 0
1363131985 2165/165/165 165:165:85" 0
1363131985 2165/165/165 165:165:85" 0
1363131985 2165/165/165 165:165:85" 0
1363131985 2165/165/165 165:165:85" 0
1363131985 2165/165/165 165:165:85" 0
1363131985 2165/165/165 165:165:85" 0
1363131985 2165/165/165 165:165:85" 0
1363131985 2165/165/165 165:165:85" 0
1363131985 2165/165/165 165:165:85" 0

Please advice.....
yusjaa5569
 
Posts: 5
Joined: Wed May 14, 2014 7:03 am

Re: ADAFRUIT SD DATALOGGER WITH RTC Problem

by adafruit_support_mike on Tue Jan 06, 2015 8:49 pm

Post the code you're using and we'll see if we can find anything.

adafruit_support_mike
 
Posts: 62799
Joined: Thu Feb 11, 2010 2:51 pm

Re: ADAFRUIT SD DATALOGGER WITH RTC Problem

by yusjaa5569 on Tue Jan 06, 2015 10:29 pm

Code: Select all | TOGGLE FULL SIZE
#include <SD.h>
#include <Wire.h>
#include "RTClib.h"
// A Weather station data logger for the Arduino
#define ECHO_TO_SERIAL   1 // echo data to serial port
#define WAIT_TO_START    0 // Wait for serial input in setup()
//1. Digital pins
#define greenLEDpin 3
#define RainPin 5
SdFile root;
// for the data logging shield, we use digital pin 10 for the SD cs line
const int chipSelect = 10;
//2. define the Real Time Clock object
RTC_DS1307 RTC;
DateTime now;
// the logging file
File dataFile;
int LogInterval;
int SampInterval=30;            //Number of seconds in the LogInterval

  //3. Rain variable
bool RainHigh=false;
const float LowAmt=0.05;    //when rain is low, takes this ml to trip
const float HiAmt=0.05;        //when rain is high, takes this ml to trip
float RainAccum=0.0;           //Rain accumulator since start of sample
// Timing counters
unsigned long StartTime;   //Log Interval counter

void error(char *str) {
  Serial.print("error: ");
  Serial.println(str);
  while(1);
  }

void setup(void) //=============================================================================================
{
  Serial.begin(9600);
  Serial.println();
  pinMode(RainPin,INPUT); 
   // Rain get start state
 
   
  LogInterval=SampInterval*1000;    //  sec between entries
 
 
  #if WAIT_TO_START
   Serial.println("Type any character to start");
   while (!Serial.available());
  #endif //WAIT_TO_START
   
  // initialize the SD card
  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);
 
// see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
      Serial.println("Card failed, or not present");
      //don't do anyhing more:
      return; }
      Serial.println("SD card initialized.");
   
// create a new file
    char filename[] = "LOGGER00.CSV";
    for (uint8_t i = 0; i < 100; i++) {
    filename[6] = i/10 + '0';
    filename[7] = i%10 + '0';
    if (! SD.exists(filename)) {
     // only open a new file if it doesn't exist
      dataFile = SD.open(filename, FILE_WRITE); 
      break; } // leave the loop!
    }
   
  if (! dataFile) {
  Serial.println("error opening log file");
  }
  // Wait forever since we cant write data
  //  while (1) ;
  Serial.print("logging to:");
  Serial.println(filename); 
   
  root.ls(LS_R | LS_DATE | LS_SIZE);
 
Wire.begin();    //-----------------------------------------------------------------------------------------------
RTC.begin();     //-----------------------------------------------------------------------------------------------

     if (! RTC.begin()) {
     dataFile.println("RTC failed");
     RTC.adjust(DateTime(__DATE__, __TIME__));
     #if ECHO_TO_SERIAL
     Serial.println("RTC failed");   
     #endif //ECHO_TO_SERIAL
      } 
   
    dataFile.println("Date, Time, RainAccum(ml)");   
    #if ECHO_TO_SERIAL // attempt to write out the header to the file
   
    Serial.println("Date, Time, RainAccum(ml)");                                           
    #endif                  //ECHO_TO_SERIAL

   // attempt to write out the header to the file
   // if (dataFile.writeError || !dataFile.sync()) {
   // error("write header"); }
   
    StartTime = millis(); //Initialize StartTime
    }


void loop(void)//========================================================================================================
{   
                                                         // clear print error
                                                         //logfile.writeError = 0;
   // Rain calculator, looks for Rain continuously
   // Look for low to high
   if ((RainHigh==false)&&(digitalRead(RainPin)==HIGH))
    {   RainHigh=true;
   RainAccum+=LowAmt;
     }
   if ((RainHigh==true)&&(digitalRead(RainPin)==LOW))
    {   RainHigh=false;
   RainAccum+=HiAmt;
     }
   
   if ((millis()-StartTime)>long(LogInterval))  // Log Interval has passed
   {
      now = RTC.now();          // fetch the time
      // log time
           dataFile.print(now.unixtime()); // seconds since 1/1/1970
                dataFile.print(", ");
                dataFile.print(now.year(), DEC);
      dataFile.print("/");
      dataFile.print(now.month(), DEC);
      dataFile.print("/");
      dataFile.print(now.day(), DEC);
      dataFile.print(", ");
      dataFile.print(now.hour(), DEC);
      dataFile.print(":");
      dataFile.print(now.minute(), DEC);
      dataFile.print(":");
      dataFile.print(now.second(), DEC);
                dataFile.print('"');
      
                #if ECHO_TO_SERIAL
                Serial.print(now.unixtime()); // seconds since 1/1/1970
                Serial.print(", ");
                Serial.print('"');
                Serial.print(now.year(), DEC);
                Serial.print("/");
                Serial.print(now.month(), DEC);
                Serial.print("/");
                Serial.print(now.day(), DEC);
                Serial.print(" ");
                Serial.print(now.hour(), DEC);
                Serial.print(":");
                Serial.print(now.minute(), DEC);
                Serial.print(":");
                Serial.print(now.second(), DEC);
                Serial.print('"');
                #endif //ECHO_TO_SERIAL      
   
   dataFile.print(", ");
   dataFile.println(RainAccum,1);
        dataFile.flush();
      
   #if ECHO_TO_SERIAL
   Serial.print(", ");   
   Serial.println(RainAccum,1);
        #endif //ECHO_TO_SERIAL   
                                                       
    
   StartTime = millis();   //Get StartTime for next LogInterval
   // Clear variables for next LogInterval
   digitalWrite(greenLEDpin, LOW);
                RainAccum=0.0;   
        // if (!file.sync()) error("sync");
   }
}
Last edited by yusjaa5569 on Thu Jan 08, 2015 12:12 am, edited 3 times in total.
yusjaa5569
 
Posts: 5
Joined: Wed May 14, 2014 7:03 am

Re: ADAFRUIT SD DATALOGGER WITH RTC Problem

by adafruit_support_bill on Wed Jan 07, 2015 6:50 am

1363131985 2165/165/165 165:165:85" 0

Output like that usually means that the clock is not running, or not communicating on the i2c bus. Check the battery - it should be ~3v between GND and the top of the battery. Also, please post some photos showing the soldering on the board.

adafruit_support_bill
 
Posts: 81321
Joined: Sat Feb 07, 2009 10:11 am

Re: ADAFRUIT SD DATALOGGER WITH RTC Problem

by yusjaa5569 on Wed Jan 07, 2015 7:15 am

Thanks a lot, its really a silly mistakes..., its works well after i change the battery.
yusjaa5569
 
Posts: 5
Joined: Wed May 14, 2014 7:03 am

Re: ADAFRUIT SD DATALOGGER WITH RTC Problem

by yusjaa5569 on Wed Jan 07, 2015 7:25 am

The only bothering me now is the sampling interval... i cant make it longer than a minutes. I am using the followings lines i d copied it from somewhere.

// the logging file
File dataFile;
int LogInterval;
int SampInterval=30; //Number of seconds in the LogInterval



LogInterval=SampInterval*1000; // sec between entries


if ((millis()-StartTime)>long(LogInterval)) // Log Interval has passed


StartTime = millis(); //Get StartTime for next LogInterval


For those setup i can gan only 30 sec interval... Any advise?
yusjaa5569
 
Posts: 5
Joined: Wed May 14, 2014 7:03 am

Re: ADAFRUIT SD DATALOGGER WITH RTC Problem

by adafruit_support_bill on Wed Jan 07, 2015 7:57 am

For those setup i can gan only 30 sec interval... Any advise?

32.767 seconds to be exact...

Code: Select all | TOGGLE FULL SIZE
int LogInterval;
int SampInterval=30; //Number of seconds in the LogInterval

LogInterval is defined as an integer. In the Arduino, that is a 16 bit signed quantity between -32768 and +32767. So you can't have an interval larger than 32767 milliseconds.

Instead, you should define it as an unsigned 32 bit character. That will let you set intervals up to 4,294,967,295 milliseconds (about 49 days).
Code: Select all | TOGGLE FULL SIZE
uint32_t LogInterval;
uint32_t SampInterval=30; //Number of seconds in the LogInterval

adafruit_support_bill
 
Posts: 81321
Joined: Sat Feb 07, 2009 10:11 am

Re: ADAFRUIT SD DATALOGGER WITH RTC Problem

by yusjaa5569 on Wed Jan 07, 2015 8:47 am

Got it ... Thank you very much...
yusjaa5569
 
Posts: 5
Joined: Wed May 14, 2014 7:03 am

Please be positive and constructive with your questions and comments.