Tuesday, January 3, 2012

Wise Clock 4 - time synchronization with GPS

This is my first foray into the world of GPS, made possible by the GPS XBee kit.
With Wise Clock 4 offering support for XBee, this little GPS module from seeedstudio seemed like a nice fit. The purpose is, of course, to synchronize the clock with the accurate time received from satellites.

Note: Some time ago I tried the WWVB atomic clock radio receiver module CMMR-6. It comes with a 60mm ferrite rod, pretty inadequate for receiving the Colorado radio signal in Toronto, more than 2200km away. On top of the fact that it is finicky (never worked for me), it is also bulky (the ferrite rod) and fragile (the thin antenna wire).

First, I inserted the module into the XBee adapter from adafruit, which is connected (through the FTDI cable) to a terminal session (9600, 8, N, 1).

Messages started flowing in, right off the bat: wow!

Next, I moved the GPS module onto the Wise Clock 4 and uploaded a sketch that uses TinyGPS library (modified by Justin).

Here is the serial monitor output.

For those who require maximum accuracy on top of the one provided by the DS3231 RTC chip itself, this GPS solution should do it.

Make the "Doomsday clock", like the one by Wyolum team shown in the video below, with Wise Clock 4 and 2 displays.

Update: Homework done.


  1. Fun homework problem! I will be looking forward to the result.


  2. While I'm not trying to make a doomsday clock I am trying to make a start clock for road rallies. I have a wise clock 4 board with atmega 1284p, gpsbee, and a pair of 32x16 LED Boards from Sure. I can not get any out put from the GPS when installed on the board. From the tinyGPS library static_test works fine. I try the GPS_time I get gps_time:38: error: 'set_1Hz_ref' was not declared in this scope. I've been chasing the problem for a while now and hope you and shed some light on my problem or provide me the minor changes that you made to the tinyGPS library.

    1. Dave,
      From what I see by looking at the gps_time sketch (coming with TinyGPS library), it requires an 1Hz interrupt on pin 2. For Wise Clock 4, this is achieved with the (red) jumper, as shown in the 3rd image of this post. (You will also need to solder R17 pullup, 10K, SMD)
      Please let me know how it goes.

    2. Hi FlorinC, I recently saw your post about using the TinyGPS with the ATmega1284P. I am trying to connect a GPS to my 1284P using TinyGPS. Everything works great when I am using the GPS with an Arduino Uno, but when I connect it to the bare bones 1284P, no data makes it to the chip (like what Dave observed below). Do you know what connections I should make to make this work on my 1284P? Thanks! Luc

    3. I am not sure about the context in your case. Are you using an RTC that generates 1Hz interrupts? What sketch are you trying to run and doesn't work?
      (I already assume that you are using the core Sanguino files for 1284?)

    4. Hi Florin, basically I built a bare bones 1284 chip with the arduino bootloader (just as shown here: http://maniacbug.wordpress.com/2011/11/27/arduino-on-atmega1284p-4/) and I am trying to add a EM-406 GPS to it. My GPS works great when connected to an Arduino Uno (pins 2 and 3) and using the "test_with_gps_device" sketch of the TinyGPS library. However, when I load the same sketch to the 1284P (and changing the software serial pins to 13 and 14) and connect my GPS to it (I already tested to make sure that the RX and TX pins are in the right order), I get no data coming in at all. Since you are able to get GPS data using your board, I was wondering if you needed special connections in order for the GPS to work for you (ie: you mentioned a "red jumper", R17 pullup, 10K, SMD, etc, in your earlier post).

    5. OK, it is more clear now.
      The GPS module used is Wise Clock 4 is the GPSBee (from seeedstudio), which communicates with the 1284 on the second UART (Tx1/Rx1), and therefore SoftwareSerial is not involved.
      In your case, I would try to connect it too on the hardware serial port (1284's pins 16 and 17).
      The jumper and the pullup resistor mentioned previously are related to the 1Hz interrupt from DS3231, so they won't apply to your case.
      Please keep me posted on your progress.

    6. Thanks Florin! I ended up connecting the GPS via the Serial1 port. Made things way easier :) Thanks so much anyway!

  3. I've added the jumper and the SMD 10k resistor, code compiles fine but I'm not getting any output from the GPS. I've tried changing the pins from 3,4 to 2,3 and 11,12 with no change in the results. The serial monitor only returns:
    I've tested the gpsbee with a an adaptor and it works fine.

  4. Forgot to add that I'm testing with the tinygps12 library and the simple test example in my last post.
    When I compile and run GPS_Time.pde I get the following:
    Testing TinyGPS library v. 9
    by Mikal Hart

    Sizeof(gpsobject) = 103

    50!=52=52 Coarse Sync
    52!=54=54 Coarse Sync
    54!=56=56 Coarse Sync
    56!=58=58 Coarse Sync
    58!=0=60 Coarse Sync
    0!=60=60 Coarse Sync
    60!=2=2 Coarse Sync
    2!=4=4 Coarse Sync
    Not sure why there is no GPS output.
    Any thoughts.

  5. OOP's I forgot to un-comment the code. Works fine now.
    But I find that the time is 2 seconds apart. I've searched the code and changed and eliminated code but still the it only runs the output every 2 seconds.I need 1 second intervals. Any thoughts.

    1. Dave,
      Use this sketch to test that the interrupt occurs every second:

      #include "Arduino.h"
      #include "Wire.h"
      #include "DS3231.h"

      int rtc[7];

      void rtc_interrupt()
      Serial.println("inside ISR");

      void setup()
      pinMode(2, INPUT);
      attachInterrupt(2, rtc_interrupt, FALLING);

      Serial.println("RTC square wave enabled");

      void loop()

      for(int i=0; i<7; i++)
      Serial.print(" ");