This is still an issue. I've some patched code that works 1/2 of the time.. I would sure like to see a Test sketch that works...
@Mem: Great Book, Was Extremely helpful... and I re-read it frequently Thank You Sir.
I took your GPS time sketch and married it to a GPS and a GLCD separately both work but:
This one fails to transfer data from the gps routines to the clock I am very tired... of looking at it, There are some debug things and the separators need to be fixed but
I have a gps unit working with a sketch I put together from harts suggestions and a graphics LCD but there were several compelling reasons to use your sketch so...
MORE at Bottom
/*
* TimeGPS_Round1.ino
* example code illustrating time synced from a GPS
*
*/
#include <Time.h>
#include <TinyGPS.h>
// GPS Library is the work of Mikal Hart
#include <UTFT.h>
extern uint8_t SmallFont[];
UTFT myGLCD(ITDB32S,38,39,40,41); // Mega2560
TinyGPS gps;
const int offset = -7; // offset hours from gps time (UTC)
time_t prevDisplay = 0; // when the digital clock was displayed
void setup()
{
myGLCD.InitLCD(); // '0' is default landscape '1' is portrait
myGLCD.setFont(SmallFont);
//myGLCD.clrScr();
//Serial1.begin(9600); // 9600 baud for Skylabs SKM53
Serial1.begin(4800); // 4800 baud for U-Blox_6-1
myGLCD.print("Waiting for GPS time ... ",8,0);
setSyncProvider(gpsTimeSync);
myGLCD.clrScr();
}
void loop()
{
while (Serial1.available())
{
gps.encode(Serial1.read()); // process gps messages
// Debug Messages
myGLCD.print("Waiting for GPS time ... ",CENTER,120); [color=red]// This works[/color]
myGLCD.printNumI(hour(),64,24,2,'0'); // Prints 2 digit hour with leading 0
//myGLCD.print(":",76 ,24); // separator not really rerquired
myGLCD.printNumI(minute(),84,24,2,'0');
myGLCD.printNumI(second(),104,24,2,'0');
// End of Debug messages
}
if(timeStatus()!= timeNotSet)
{
if( now() != prevDisplay) //update the display only if the time has changed
{
myGLCD.print("Waiting for GPS time ... ",CENTER,110); [color=orange]//This doesn't it never gets here[/color]
prevDisplay = now();
digitalClockDisplay();
}
}
}
void digitalClockDisplay(){
// digital clock display of the time
myGLCD.setColor(255,255,0);
myGLCD.print("Date :",8 ,8);
myGLCD.printNumI(month(),64,8,2,'0'); // Prints 2 digit month with leading 0
myGLCD.print("/",80 ,8); //
myGLCD.printNumI(day(),88,8,2,'0'); // Prints 2 digit day with leading 0
myGLCD.print("/20",104,8);
myGLCD.printNumI(year(),112,8);
myGLCD.print("Time :",8 ,24);
myGLCD.printNumI(hour(),64,24,2,'0'); // Prints 2 digit hour with leading 0
//myGLCD.print(":",76 ,24); // separator not really rerquired
myGLCD.printNumI(minute(),84,24,2,'0');
// myGLCD.print(":",94 ,24);
myGLCD.printNumI(second(),104,24,2,'0');
}
/* NOT REQUIRED, UTFT LIB DOES THIS NICELY
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);
}
*/
time_t gpsTimeSync(){
// returns time if avail from gps, else returns 0
unsigned long fix_age = 0 ;
gps.get_datetime(NULL,NULL, &fix_age);
//unsigned long time_since_last_fix; // *****COMMENTING OUT THIS***** [b]Yeah I know this is stupid... but when I did it I was too @ 4:00 AM <BG>[/b]
// if(fix_age < 1000) // *****AND THIS*****
return gpsTimeToArduinoTime(); // return time only if updated recently by gps
// return 0; // *****FIXED THE ISSUE... Why is an issue??*****
}
time_t gpsTimeToArduinoTime()
{
myGLCD.print("Waiting for GPS time ... ",CENTER,90);
// returns time_t from gps date and time with the given offset hours
tmElements_t tm;
int year;
gps.crack_datetime(&year, &tm.Month, &tm.Day, &tm.Hour, &tm.Minute, &tm.Second, NULL, NULL);
tm.Year = year - 1970;
time_t time = makeTime(tm);
return time + (offset * SECS_PER_HOUR);
}
{Edit //COMMENT Are the things I changed
Any Help would be appreciated I attached the file W/O the commented mods described above.
{Edit. I added the finished metrology functions to the basic timeGPS Sketch and used an Itead 3.2 GLCD because of the really nice libs that come with it.
UTFT By Henning Karlsen works well with the Itead product... At about $17.00 a copy for a 3.2" 320X240 display it's hard to beat (W/Touch & SDcard)
Bob
TimeGPS_GLCD_Round1.ino (2.9 KB)
Time_Baro_R_H__GLCD_R1_2.ino (5.64 KB)