{"id":8464,"date":"2019-08-25T14:26:55","date_gmt":"2019-08-25T14:26:55","guid":{"rendered":"https:\/\/stevepedwards.today\/stevepedwards.com\/ElectronicsStuff\/?p=8464"},"modified":"2019-08-25T14:26:55","modified_gmt":"2019-08-25T14:26:55","slug":"how-to-display-your-gps-nmea-data-in-google-earth","status":"publish","type":"post","link":"https:\/\/stevepedwards.today\/ElectronicsStuff\/how-to-display-your-gps-nmea-data-in-google-earth\/","title":{"rendered":"How to display your Arduino GPS NMEA data in Google Earth"},"content":{"rendered":"<div id=\"wpwrap\">\n<div id=\"adminmenumain\" role=\"navigation\" aria-label=\"Main menu\"><span style=\"color: #0000ff;\"><em>\"When selective availability was lifted in 2000, GPS had about a five-meter (16 ft) accuracy. The latest stage of accuracy enhancement uses the L5 band and is now fully deployed. GPS receivers released in 2018 that use the L5 band can have much higher accuracy, pinpointing to within 30 centimetres or 11.8 inches\"<\/em><\/span><br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/stevepedwards.today\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/b\/b4\/Comparison_satellite_navigation_orbits.svg\/250px-Comparison_satellite_navigation_orbits.svg.png\" width=\"485\" height=\"485\" \/><br \/>\nAn empty sketch Serial Monitor view shows live NMEA data from your GPS module:<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8465\" src=\"https:\/\/stevepedwards.today\/ElectronicsStuff\/wp-content\/uploads\/2019\/08\/nmea.png\" alt=\"\" width=\"930\" height=\"1017\" \/><br \/>\nFor GEarth, Lat Long of:<br \/>\n$GNGLL,5014.6947,N,00515.7258,W,135203.000<br \/>\nbecomes:<br \/>\n50 14.6947N 005 15.7258W<br \/>\nPaste into Search bar:<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8466\" src=\"https:\/\/stevepedwards.today\/ElectronicsStuff\/wp-content\/uploads\/2019\/08\/local_nmea_pos.png\" alt=\"\" width=\"480\" height=\"258\" \/><br \/>\nGNRMC,135203.000 is the time GMT:<br \/>\n13:52:03<br \/>\nIf you want to use linux tools for parsing particular data, a simple example to start when you have loaded a blank sketch and seeing all the GPS data in the serialmon, is to view that with socat in a terminal instead, then parse what you want with awk, which could then be sent to a text or data file using e.g. &gt; RMCtext.txt at the end:<\/p>\n<pre class=\"\">socat stdio \/dev\/ttyACM0 | awk '\/'GNRMC'\/ {print }'<\/pre>\n<p>this gives only $*RMC lines:<\/p>\n<pre class=\"\">socat stdio \/dev\/ttyACM0 | awk '\/'GNRMC'\/ {print }'<\/pre>\n<p><span style=\"color: #ff0000;\">$GNRMC,163013.000,A,5014.6943,N,00515.7251,W,0.00,10.80,250819,,,A*52<\/span><br \/>\n<span style=\"color: #ff0000;\">$GNRMC,163014.000,A,5014.6943,N,00515.7251,W,0.00,10.80,250819,,,A*55<\/span><br \/>\nIf you want both the RMC and GGA lines shown in the vid parsed :<\/p>\n<pre class=\"\">socat stdio \/dev\/ttyACM0 | awk '\/'GNRMC'|'GNGGA'\/ {print }'<\/pre>\n<p><span style=\"color: #ff0000;\">$GNRMC,165830.000,A,5014.6945,N,00515.7270,W,0.00,10.80,250819,,,A*58 $GNGGA,165831.000,5014.6945,N,00515.7271,W,1,08,1.2,140.4,M,0.0,M,,*6E-\u00a0<\/span><br \/>\nIf you want to separate these comma-\u00a0 delimited fields and print one or more only:<\/p>\n<pre class=\"\">socat stdio \/dev\/ttyACM0 | awk 'BEGIN{FS=\",\"} \/'GNRMC'|'GNGGA'\/ {print $2}'\n<\/pre>\n<p><span style=\"color: #ff0000;\">171104.000<\/span><br \/>\n<span style=\"color: #ff0000;\">171105.000<\/span><br \/>\nFor time and Lat\/Long on one line:<\/p>\n<pre class=\"\">socat stdio \/dev\/ttyUSB0 | awk 'BEGIN{FS=\",\"} \/'GNGGA'\/ {print $2,$3,$4,$5,$6}'<\/pre>\n<p><span style=\"color: #ff0000;\">010837.000 5014.6967 N 00515.7299 W<\/span><br \/>\n<span style=\"color: #ff0000;\">010838.000 5014.6966 N 00515.7298 W<\/span><br \/>\n<span style=\"color: #ff0000;\">010839.000 5014.6965 N 00515.7298 W<\/span><br \/>\nThe Lat\/Long is decimal not degrees so would have to be calculated. A first step is isolate the degrees by dividing by 100 and -100 for West:<\/p>\n<pre class=\"\">socat stdio \/dev\/ttyUSB0 | awk 'BEGIN{FS=\",\"} \/'GNGGA'\/ {print $2,$3\/100,$4,$5\/-100,$6}'<\/pre>\n<p><span style=\"color: #ff0000;\">011454.000 50.1469 N -5.15732 W<\/span><br \/>\n<span style=\"color: #ff0000;\">011455.000 50.1469 N -5.15732 W<\/span><br \/>\nCo-ords for Gmaps takes the form:<\/p>\n<pre class=\"lang:default decode:true \">socat stdio \/dev\/ttyUSB0 | awk '\/'GNGLL'\/ {FS=\",\"; print $2\/100(10),$4\/-100}'<\/pre>\n<p><span style=\"color: #ff0000;\">50.146910 -5.15727 <\/span>in decimal degrees format which Gmaps accepts, but is about 10km out:<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8472\" src=\"https:\/\/stevepedwards.today\/ElectronicsStuff\/wp-content\/uploads\/2019\/08\/DECGPSOUT.png\" alt=\"\" width=\"444\" height=\"330\" srcset=\"https:\/\/stevepedwards.today\/ElectronicsStuff\/wp-content\/uploads\/2019\/08\/DECGPSOUT.png 707w, https:\/\/stevepedwards.today\/ElectronicsStuff\/wp-content\/uploads\/2019\/08\/DECGPSOUT-300x223.png 300w\" sizes=\"auto, (max-width: 444px) 100vw, 444px\" \/><br \/>\nMiles out in Gmaps, even with a conversion from decimal to DMS. How does that work?<br \/>\nFull circle = 360 x 60 x 60 = 1,296,000 DMS secs.<br \/>\nFirst divide GPS decimal value by 100 to get degrees (first error there surely?)<br \/>\n50.146910, then multiply fraction 0.146910 by 60 = <strong>8<\/strong>.81892 mins.<br \/>\nthen multiply fraction 0.146982 mins by 60 = <strong>48<\/strong>.876 secs<br \/>\n50 deg, 8 mins, 49.1 secs N<br \/>\nSame for Long:<br \/>\n-5.15727W = -5 deg, .15727 x 60 = 9.4362 mins, .4362 x 60 = 26.172 secs<br \/>\n-5 deg, 9 mins, 26.172 secs W<br \/>\nGmaps needs format: <strong>50-\u00b08'49.1''N-\u00a0 5-\u00b09'26''W<\/strong><br \/>\n50-\u00b014'41.7\"N 5-\u00b015'43.5\"W<br \/>\n(1 degree is 1 NM of earth curvature at sea level, hence ship's\/plane's speed in knots etc.)<br \/>\n<strong>In summary for programming a parser: ALL YOU HAVE TO DO FOR BEST REAL ACCURACY in GMaps is format to the above: 50 14.6947N 005 15.7258W:<\/strong><br \/>\nTake the GPS VALUES E.G.:-\u00a0 5014.6973,N,00515.7277,W<br \/>\ncreate a single space 2 dec places before the decimal point for each field, leave the point alone:<br \/>\n<strong> 50 14.6973,N<\/strong><br \/>\nStrip the trailing comma before \",N\":<br \/>\n<strong>50 14.6973N-\u00a0<\/strong><br \/>\nstrip a space between the next fields then same for next coord.:<br \/>\n50 14.6973N 005 15.7277W<br \/>\nSo far, very crude, but works..I love sed!:<\/p>\n<pre class=\"lang:default decode:true \">socat stdio \/dev\/ttyUSB0 | awk 'BEGIN{FS=\",\"} \/'GNGLL'\/ {print $2,$3,$4,$5} fflush()' | sed -u 's\/ \/\/g' | sed -u 's\/^..\/&amp; \/g'| sed -u 's\/^...........\/&amp; \/g' | sed -u 's\/^...............\/&amp; \/g'<\/pre>\n<p><span style=\"color: #ff0000;\">50 14.6956N 005 15.7257W<\/span><br \/>\nNow fire it into Gmaps:??<br \/>\nYou can simulate the GPS stream if working away from the unit on your pipe one liner, something like:<\/p>\n<pre class=\"lang:default decode:true\">while sleep 1 ; do  printf \"\\$GNGLL,5014.6947,N,00515.7258,W,135203.000\\n\" ; done | awk 'BEGIN{FS=\",\"} \/'GNGLL'\/ {print $2,$3,$4,$5} fflush()'  | sed -u 's\/ \/\/g' | sed -u 's\/^..\/&amp;+\/g' | sed -u 's\/N\/&amp;%20\/g' | sed -u 's\/^.................\/&amp;+\/g' | head -n 1 | xargs google-chrome https:\/\/www.google.com\/search?q=<\/pre>\n<p>The above GPS socat could be used with a Pi as a data logger, if various Arduino GPS parsing examples from the web like the one below doesn't work for you, as they did not for my Neo7, because it's for the Adafruit GPS library and module:<\/p>\n<pre class=\"lang:default decode:true \">\/\/https:\/\/stevepedwards.today\/core-electronics.com.au\/tutorials\/how-to-use-gps-with-arduino.html\n#include &lt;Adafruit_GPS.h&gt;\n\/\/#include &lt;Adafruit_GPS.h&gt;\n\/\/We can now create our Software Serial object after including the library\nSoftwareSerial mySerial(3, 2);\n\/\/And finally attach our Serial object pins to our GPS module\nAdafruit_GPS GPS(&amp;mySerial);\nvoid setup() {\nSerial.begin(115200); \/\/This baud rate will help a lot in printing all of the data that comes from the GPS Module to the serial monitor\nGPS.begin(9600);\n\/\/These lines configure the GPS Module\nGPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); \/\/Sets output to only RMC and GGA sentences\nGPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); \/\/Sets the output to 1\/second. If you want you can go higher\/lower\n\/\/GPS.sendCommand(PGCMD_ANTENNA); \/\/Can report if antenna is connected or not\n}\nvoid loop() {\n\/\/Now we will start our GPS module, parse (break into parts) the Last NMEA sentence\nGPS.parse(GPS.lastNMEA()); \/\/This is going to parse the last NMEA sentence the Arduino has received, breaking it down into its constituent parts.\nGPS.newNMEAreceived(); \/\/This will return a boolean TRUE\/FALSE depending on the case.\n\/\/Print the current date\/time\/etc\n    Serial.print(\"\\nTime: \");\n    Serial.print(GPS.hour, DEC); Serial.print(':');\n    Serial.print(GPS.minute, DEC); Serial.print(':');\n    Serial.print(GPS.seconds, DEC); Serial.print('.');\n    Serial.println(GPS.milliseconds);\n    Serial.print(\"Date: \");\n    Serial.print(GPS.day, DEC); Serial.print('\/');\n    Serial.print(GPS.month, DEC); Serial.print(\"\/20\");\n    Serial.println(GPS.year, DEC);\n    Serial.print(\"Fix: \"); Serial.print((int)GPS.fix);\n    Serial.print(\" quality: \"); Serial.println((int)GPS.fixquality);\n\/\/If GPS module has a fix, line by line prints the GPS information\n    if (GPS.fix) {\n      Serial.print(\"Location: \");\n      Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);\n      Serial.print(\", \");\n      Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);\n      Serial.print(\"Location (in degrees, works with Google Maps): \");\n      Serial.print(GPS.latitudeDegrees, 4);\n      Serial.print(\", \");\n      Serial.println(GPS.longitudeDegrees, 4);\n      Serial.print(\"Speed (knots): \"); Serial.println(GPS.speed);\n      Serial.print(\"Angle: \"); Serial.println(GPS.angle);\n      Serial.print(\"Altitude: \"); Serial.println(GPS.altitude);\n      Serial.print(\"Satellites: \"); Serial.println((int)GPS.satellites);\n    }\n}<\/pre>\n<p>My Neo 7 data gives a specific Lat\/Long line that needs modifying to be Google Earth friendly, where field $2 is decimal Lat North, and field $4 is Long West:<br \/>\n$GNGLL,5014.6953,N,00515.7249,W,171828.000,A,A*50<br \/>\nthe time data GMT is in field $2, 17:23:07 :<br \/>\n$GNGGA,<span style=\"color: #ff0000;\"><strong>172307.000<\/strong><\/span>,5014.6953,N,00515.7244,W,1,10,1.1,141.9,M,0.0,M,,*61\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\"When selective availability was lifted in 2000, GPS had about a five-meter (16 ft) accuracy. The latest stage of accuracy enhancement uses the L5 band and is now fully deployed. GPS receivers released in 2018 that use the L5 band can have much higher accuracy, pinpointing to within 30 centimetres or 11.8 inches\" An empty <a href=\"https:\/\/stevepedwards.today\/ElectronicsStuff\/how-to-display-your-gps-nmea-data-in-google-earth\/\" class=\"more-link\">...<span class=\"screen-reader-text\">  How to display your Arduino GPS NMEA data in Google Earth<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,2],"tags":[],"class_list":["post-8464","post","type-post","status-publish","format-standard","hentry","category-tech-studies","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/stevepedwards.today\/ElectronicsStuff\/wp-json\/wp\/v2\/posts\/8464","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/stevepedwards.today\/ElectronicsStuff\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stevepedwards.today\/ElectronicsStuff\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stevepedwards.today\/ElectronicsStuff\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/stevepedwards.today\/ElectronicsStuff\/wp-json\/wp\/v2\/comments?post=8464"}],"version-history":[{"count":0,"href":"https:\/\/stevepedwards.today\/ElectronicsStuff\/wp-json\/wp\/v2\/posts\/8464\/revisions"}],"wp:attachment":[{"href":"https:\/\/stevepedwards.today\/ElectronicsStuff\/wp-json\/wp\/v2\/media?parent=8464"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stevepedwards.today\/ElectronicsStuff\/wp-json\/wp\/v2\/categories?post=8464"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stevepedwards.today\/ElectronicsStuff\/wp-json\/wp\/v2\/tags?post=8464"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}