DS3234

that is what is giving me the false numbers and here is the file I had just downloaded from DS3234 - Rinky-Dink Electronics

DS3234.cpp (8.96 KB)

DS3234.h (2.8 KB)

keywords.txt (621 Bytes)

Can you go back to your original sketch, that requires T?????????? sync message, and make the change I proposed, and let me know the results?

Regards,

Graham

I got you, I was trying to put it into the wrong sketch. It will not compile

#include <Time.h>
#include <DS3234.h>

//This section retrieves the system time (unix) in a more manageable h,m,s... format

#define TIME_MSG_LEN  11   // time sync to PC is HEADER followed by Unix time_t as ten ASCII digits
#define TIME_HEADER  'T'   // Header tag for serial time sync message
#define TIME_REQUEST  7    // ASCII bell character requests a time sync message 

// T1262347200  //noon Jan 1 2010

void setup()  {
  Serial.begin(9600);
}

void loop() {
  if (Serial.available() )
  {
    processSyncMessage();
  }
  if (timeStatus() == timeNotSet)
    Serial.println("waiting for sync message");
  else
    digitalClockDisplay();
  delay(1000);
}

void digitalClockDisplay() {
  // digital clock display of the time
  Serial.println(rtc.getTimeStr(FORMAT_LONG);
//                 Serial.print(hour());
//                 printDigits(minute());
//                 printDigits(second());
//                 Serial.print(" ");
//                 Serial.print(day());
//                 Serial.print(" ");
//                 Serial.print(month());
//                 Serial.print(" ");
//                 Serial.print(year());
//                 Serial.println();
}

void printDigits(int digits) {
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if (digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

void processSyncMessage() {
  // if time sync available from serial port, update time and return true
  while (Serial.available() >=  TIME_MSG_LEN ) { // time message consists of header & 10 ASCII digits
    char c = Serial.read() ;
    Serial.print(c);
    if ( c == TIME_HEADER ) {
      time_t pctime = 0;
      for (int i = 0; i < TIME_MSG_LEN - 1; i++) {
        c = Serial.read();
        if ( c >= '0' && c <= '9') {
          pctime = (10 * pctime) + (c - '0') ; // convert digits to a number
        }
      }
      setTime(pctime);   // Sync Arduino clock to the time received on the serial port
    }
  }
}


/* Then the user needs to open terminal and run the following command:

  sudo echo "T$(($(date +%s)+60*60-5))" >/dev/tty.usbmodem1421

where -5 is the time zone adjustment from GMT and tty.usbmodem1421 is your serial port
*/

/* This was the original way to manually set the RTC time:


*/[code]

Arduino: 1.6.1 (Windows 7), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

timesync.ino: In function 'void digitalClockDisplay()':

timesync.ino:31:18: error: 'rtc' was not declared in this scope

Error compiling.

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

IDIOT!!! i missed a closing bracket!!!

Serial.println(rtc.getTimeStr(FORMAT_LONG));

That will compile :wink:

Sorry

Graham

same error, Arduino: 1.6.1 (Windows 7), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

timesync.ino: In function 'void digitalClockDisplay()':

timesync.ino:31:18: error: 'rtc' was not declared in this scope

Error compiling.

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

I had another thought, remove your TFT shield and LCD if you haven't done so already.

Change your CS_pin to 53. (Currently 8 ) and change the wire of course too....

Graham

I see.........I just noticed WHY nothing is working in that sketch!! :roll_eyes:

Because there was NO initialising being done....!

Try this?? But also, first please do as I requested and change your CS pin wire to 53......

#include <Time.h>
#include <DS3234.h>
DS3234 rtc(53);

//This section retrieves the system time (unix) in a more manageable h,m,s... format

#define TIME_MSG_LEN  11   // time sync to PC is HEADER followed by Unix time_t as ten ASCII digits
#define TIME_HEADER  'T'   // Header tag for serial time sync message
#define TIME_REQUEST  7    // ASCII bell character requests a time sync message 

// T1262347200  //noon Jan 1 2010

void setup()  {
  Serial.begin(9600);
  rtc.begin();
}

void loop() {
  if (Serial.available() )
  {
    processSyncMessage();
  }
  if (timeStatus() == timeNotSet)
    Serial.println("waiting for sync message");
  else
    digitalClockDisplay();
  delay(1000);
}

void digitalClockDisplay() {
  // digital clock display of the time
  Serial.println(rtc.getTimeStr(FORMAT_LONG));
  /*  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year());
  Serial.println();*/
}

void printDigits(int digits) {
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if (digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

void processSyncMessage() {
  // if time sync available from serial port, update time and return true
  while (Serial.available() >=  TIME_MSG_LEN ) { // time message consists of header & 10 ASCII digits
    char c = Serial.read() ;
    Serial.print(c);
    if ( c == TIME_HEADER ) {
      time_t pctime = 0;
      for (int i = 0; i < TIME_MSG_LEN - 1; i++) {
        c = Serial.read();
        if ( c >= '0' && c <= '9') {
          pctime = (10 * pctime) + (c - '0') ; // convert digits to a number
        }
      }
      setTime(pctime);   // Sync Arduino clock to the time received on the serial port
    }
  }
}


/* Then the user needs to open terminal and run the following command:

  sudo echo "T$(($(date +%s)+60*60-5))" >/dev/tty.usbmodem1421

where -5 is the time zone adjustment from GMT and tty.usbmodem1421 is your serial port
*/

/* This was the original way to manually set the RTC time:


*/

done and done and uploaded. displaying time only as 0349 as of now, seconds incrementing up and the minute changes after 60 seconds

I am very pleased to hear it!! :smiley:

Now try changing the line in display clock to this?

Serial.println(rtc.getTimeStr());

You SHOULD be seeing seconds also.....

and also sprinkle in some of these......

Serial.println(rtc.getTimeStr());
Serial.println(rtc.getDateStr());
Serial.println(rtc.getDOWStr());
Serial.println(rtc.getMonthStr());

There are ways of setting your clock......... but none of them would be SUPER accurate.....

One example.......

Create your sketch in advance....... something like this.....

void processSyncMessage() {
  // if time sync available from serial port, update time and return true
  while (Serial.available() >=  TIME_MSG_LEN ) { // time message consists of header & 10 ASCII digits
    char c = Serial.read() ;
    Serial.print(c);
    if ( c == TIME_HEADER ) {
      time_t pctime = 0;
      for (int i = 0; i < TIME_MSG_LEN - 1; i++) {
        c = Serial.read();
        if ( c >= '0' && c <= '9') {
          pctime = (10 * pctime) + (c - '0') ; // convert digits to a number
        }
      }
      setTime(pctime);   // Sync Arduino clock to the time received on the serial port
      rtc.setTime( 07, 49, 00);
      rtc.setDate( 04, 04, 2015);
      rtc.setDOW(SATURDAY);
    }
  }
}

And then at EXACTLY 7.49:00 send your T1428179212. The time that is actually set in the RTC will be 7.49.00 april 4 2015 Saturday......

SHOULD get you close enough to real time... :wink:

Best wishes, and kindly give me some karma if you are happy with my help,

Graham

ok so here is where I am at in all the details. with the sd card unplugged and rtc in pin 53 using your code it uploads and keeps time. I was then able to upload another code and the time was the same. pin was moved from 53 to 8 and re-uploaded and things still work. using another sketch I was able to change time and date and upload with no problem. as soon as I plug the sd back in its all zeros again. so the problem then is a conflict between the rtc and the sd reader on the spi bus correct? how do I go about fixing that?

Now that is a whole different ballgame!! Get a DS3231 :wink: Sorry I cannot help further, my knowledge of multiple SPI devices on the Mega is limited/none. The DS3231 is also super accurate like the DS3234, but uses I2C, not SPI.

Hope you appreciate the help I have given to this point.

Regards,

Graham

No problem and thanks for all the help. Hopefully someone else will be able to help.