Prototype GPS Clock

arduino_gps_clock_prototype_9060I’ve cobbled together a quick prototype GPS clock from an Arduino UNO, SPI-driven LED display, and UBlox NEO-6 GPS module. Using parts bought on-line, this can be done for less than $20 USD.

Arduino makes a quick/easy prototyping platform, though I’ll probably write everything myself on a “raw” AVR for the best performance in the end. Still, this works pretty well.

/*
 * Prototype LED clock from GPS module.
 *
 * Arduino Pin 10 -> LED CS
 * Arudino pin 11 -> LED Data In
 * Arduino pin 13 -> LED CLK
 * GPS Tx -> Arduino pin 0 (Rx)
 */

#include <SPI.h>

const int CS_PIN = 10;

void setup() {

  // initialize serial (from GPS)
  Serial.begin(9600);

  // set the slaveSelectPin as an output
  pinMode(CS_PIN, OUTPUT);
  digitalWrite(CS_PIN, HIGH);

  // initialize SPI
  SPI.begin();
  
  // initialize the LED
  LED_send_pair(0x09, 0xff); // BCD mode
  LED_send_pair(0x0b, 0x07); // scan limit 8 digits (all)
  for (unsigned char i = 1; i <= 8; i++) {
    LED_send_pair(i, 0x0f); // blank digit
  }
  LED_send_pair(0x0a, 0x02); // display intensity
  LED_send_pair(0x0c, 0x01); // disable shutdown (turn on)
}


void LED_send_pair(unsigned char b1, unsigned char b2) {
  digitalWrite(CS_PIN, LOW);
  SPI.transfer(b1);
  SPI.transfer(b2);
  digitalWrite(CS_PIN, HIGH);
  delay(5);
}

void loop() {

  // this works for prototype, but is TOO SLOW
  String s = Serial.readStringUntil('\n');
  
  if (s.startsWith("$GPGGA")) {
    char ss0 = s.charAt(12);
    char ss1 = s.charAt(11);
    char mm0 = s.charAt(10);
    char mm1 = s.charAt(9);
    char hh0 = s.charAt(8);
    char hh1 = s.charAt(7);

    LED_send_pair(1, ss0 - '0');
    LED_send_pair(2, ss1 - '0');

    LED_send_pair(4, mm0 - '0');
    LED_send_pair(5, mm1 - '0');

    LED_send_pair(7, hh0 - '0');
    LED_send_pair(8, hh1 - '0');
  }
}

One thought on “Prototype GPS Clock”

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>