I’ve always enjoyed playing about with time. Accurate time is not really a fascination but I do like a clock to tell the time. The MSF 60khz time signal is one source and I have played about with that system with an Arduino and it works well, when there is a good signal for a whole minute. GPS time has always been a bit of a thing for me because you can set it to UTC and it’ll always show UTC and frankly there are a lot more libraries available to play with. GPS Tiny & GPS Tiny+ are two of those and this evening I ‘forked’ a sketch to use a cheapo off the shelf gps module to tell the time and date on a 16×2 LCD. Nothing spectacular but hey if I can do it then so can anyone. Here’s a short sweet video of it in action (near the window!)

sketch goes a little like this


#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
/*
This sample sketch demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object.
It requires the use of SoftwareSerial, and assumes that you have a
4800-baud serial GPS device hooked up on pins 8(rx) and 9(tx).
*/
static const int RXPin = 8, TXPin = 9;
static const uint32_t GPSBaud = 9600;
// The TinyGPS++ object
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
ss.begin(GPSBaud);
lcd.begin(16,2);
lcd.setCursor(1,0);
lcd.print("Tiny GPS+ Time");
delay(3000);
lcd.setCursor(1,2);
lcd.print("by Alex, g7kse");
delay(5000);
lcd.clear();
}
void loop()
{
// This sketch displays information every time a new sentence is correctly encoded.
while (ss.available() > 0)
if (gps.encode(ss.read()))
displayInfo();
if (millis() > 5000 && gps.charsProcessed() < 10)
{
lcd.print("No GPS detected");
for (int positionCounter = 0; positionCounter < 20; positionCounter++) {
while(true);
}
}
}
void displayInfo()
{
lcd.setCursor(4,0);
{
if (gps.time.hour() < 10) lcd.print(F("0"));
lcd.print(gps.time.hour());
lcd.print(F(":"));
if (gps.time.minute() < 10) lcd.print(F("0"));
lcd.print(gps.time.minute());
lcd.print(F(":"));
if (gps.time.second() < 10) lcd.print(F("0"));
lcd.print(gps.time.second());
}
lcd.setCursor(3,2);
{
if (gps.date.day() < 10) lcd.print(F("0"));
lcd.print(gps.date.day());
lcd.print(F("/"));
if (gps.date.month() < 10) lcd.print(F("0"));
lcd.print(gps.date.month());
lcd.print(F("/"));
lcd.print(gps.date.year());
}
}

Leave a Reply