read GPS NMEA data to get UTC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // GPS clock | |
| // UTCdata get from NMEA $GPGGA field $2 | |
| // | |
| // for Arduino Leonardo / Seeeduino Lite(3.3V) | |
| void setup() { | |
| Serial1.begin(9600); // GPS port | |
| while(!Serial1) delay(10); | |
| Serial.begin(9600); // Console | |
| while(!Serial) delay(10); | |
| } | |
| int hh,mm,ss ; | |
| const int TD = 9; | |
| void loop() { | |
| if (Serial1.available()) { | |
| String nmea = Serial1.readStringUntil('\n'); | |
| String nmeames = nmea.substring(0,6); // $GP*** | |
| if ( nmeames.equals("$GPGGA") ) { // get UTC | |
| String shh = nmea.substring(7,9); | |
| String smm = nmea.substring(9,11); | |
| String sss = nmea.substring(11,13); | |
| // Serial.println(shh + smm + sss); | |
| hh = (shh.toInt() + TD)%24; // Timezone offset+ | |
| mm = smm.toInt(); | |
| ss = sss.toInt(); | |
| Serial.print(hh); | |
| Serial.print(":"); | |
| Serial.print(mm); | |
| Serial.print(":"); | |
| Serial.println(ss); | |
| } | |
| } | |
| // if (Serial1.available()) Serial.write(Serial1.read()); | |
| // if (Serial.available()) Serial1.write(Serial.read()); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment