[time-nuts] Portable Time Standard

Jim Harman j99harman at gmail.com
Thu Mar 7 14:09:40 UTC 2019


Here is an example Arduino sketch that controls the DS3231, blinks the
Arduino's LED, and displays the current time and temperature on the
controlling PC, using the Arduino Wire and Chronodot libraries. For even
better precision, you would want to run the PPS line to an interrupt and
use an ISR to control real-time operations.

This does not power down the processor between updates.
----------------------------------------------
// Date, time and temperature functions using
// a Chronodot RTC connected via I2C and Wire lib

#include <Wire.h>
#include "Chronodot.h"

Chronodot RTC;
byte led = 13;      //LED pin
char offset = 11;    //value for aging register

void setup () {
    Serial.begin(9600);
    Serial.println("Initializing Chronodot.");

    Wire.begin();
    RTC.begin();

    pinMode(led, OUTPUT);

  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
  }
  //coarse adjustment - set to compile time
  //RTC.adjust(DateTime(__DATE__, __TIME__));

  //setup square wave output for 1 Hz
  Wire.beginTransmission(0x68);
Wire.write((byte)0x0E);
Wire.write((byte)0);
Wire.endTransmission();

  //setup drift offset approx 0.1 ppm/count
  Wire.beginTransmission(0x68);
Wire.write((byte)0x10);
Wire.write(offset);
Wire.endTransmission();

    Serial.println("Enter adjustment in seconds");
  }

void loop () {
    DateTime now = RTC.now();

    //blink the LED on the minute
    digitalWrite(led, now.second() == 0);

    if(now.second() % 5 == 0) {
      Serial.print(now.year(), DEC);
      Serial.print('/');
      if(now.month() < 10) Serial.print("0");
      Serial.print(now.month(), DEC);
      Serial.print('/');
      if(now.day() < 10) Serial.print("0");
      Serial.print(now.day(), DEC);
      Serial.print(' ');
      if(now.hour() < 10) Serial.print("0");
      Serial.print(now.hour(), DEC);
      Serial.print(':');
      if(now.minute() < 10) Serial.print("0");
      Serial.print(now.minute(), DEC);
      Serial.print(':');
      if(now.second() < 10) Serial.print("0");
      Serial.print(now.second(), DEC);
      Serial.println();

      Serial.print(now.tempC(), 1);
      Serial.println(" degrees Celsius");
      Serial.print(now.tempF(), DEC);
      Serial.println(" degrees Farenheit");

      Serial.println();
      delay(1000);

      if(!Serial.available()) return;

      //got an adjustment
      int adj = Serial.parseInt();

      DateTime now = RTC.now();

      //get the current time as an integer
      uint32_t t = now.unixtime();
      t += adj;

      RTC.adjust(t);

      Serial.print("adjustment ");
      Serial.println(adj);


    }
}
---------------------------------------------------------------------------
On Thu, Mar 7, 2019 at 8:14 AM Jim Harman <j99harman at gmail.com> wrote:

> For ease of programming and reasonably low power consumption I would look
> into an Arduino.
>
>>
>>

-- 

--Jim Harman



More information about the Time-nuts_lists.febo.com mailing list