{"id":1514,"date":"2018-05-04T16:06:04","date_gmt":"2018-05-04T20:06:04","guid":{"rendered":"http:\/\/www.xavignu.com\/?p=1514"},"modified":"2018-05-04T16:06:04","modified_gmt":"2018-05-04T20:06:04","slug":"gps-on-orange-pi-2g-iot","status":"publish","type":"post","link":"https:\/\/www.xavignu.com\/?p=1514","title":{"rendered":"GPS on Orange Pi 2G IOT"},"content":{"rendered":"<p>Recently I got myself a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Global_Positioning_System\" target=\"_blank\">GPS<\/a> module to play with such as <a href=\"https:\/\/www.u-blox.com\/en\/product\/neo-6-series\" target=\"_blank\">this<\/a>. Not that I knew much about but felt like something nice to play with. First thing first is connecting the GPS module to the GPIO in <a href=\"http:\/\/www.orangepi.org\/OrangePi2GIOT\/\" target=\"_blank\">Orange Pi 2G<\/a>. In my case I decided to connect the GPS to ttyS2, asides from VCC (2.8V) and GND. This correspond to pins 1, 6, 8 and 10.<br \/>\nVcc -> pin 1<br \/>\nGND -> pin 6<br \/>\nTxD -> pin 8<br \/>\nRxD -> pin 10<br \/>\n<a href=\"http:\/\/www.xavignu.com\/wp-content\/uploads\/2018\/05\/OrangePI-2G-IOT-PINOUT-GPIO.2.2-300x300.png\"><img loading=\"lazy\" src=\"http:\/\/www.xavignu.com\/wp-content\/uploads\/2018\/05\/OrangePI-2G-IOT-PINOUT-GPIO.2.2-300x300.png\" alt=\"\" width=\"300\" height=\"300\" class=\"aligncenter size-full wp-image-1516\" srcset=\"https:\/\/www.xavignu.com\/wp-content\/uploads\/2018\/05\/OrangePI-2G-IOT-PINOUT-GPIO.2.2-300x300.png 300w, https:\/\/www.xavignu.com\/wp-content\/uploads\/2018\/05\/OrangePI-2G-IOT-PINOUT-GPIO.2.2-300x300-150x150.png 150w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nPin 1 would be the one just below a small white arrow to the left of the SD card. Below two pictures of GPS connected to Orange Pi GPIO pins.<br \/>\n<a href=\"http:\/\/www.xavignu.com\/wp-content\/uploads\/2018\/05\/GPS1.jpg\"><img loading=\"lazy\" src=\"http:\/\/www.xavignu.com\/wp-content\/uploads\/2018\/05\/GPS1.jpg\" alt=\"\" width=\"1024\" height=\"768\" class=\"aligncenter size-full wp-image-1520\" srcset=\"https:\/\/www.xavignu.com\/wp-content\/uploads\/2018\/05\/GPS1.jpg 1024w, https:\/\/www.xavignu.com\/wp-content\/uploads\/2018\/05\/GPS1-300x225.jpg 300w, https:\/\/www.xavignu.com\/wp-content\/uploads\/2018\/05\/GPS1-768x576.jpg 768w, https:\/\/www.xavignu.com\/wp-content\/uploads\/2018\/05\/GPS1-624x468.jpg 624w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><br \/>\n<a href=\"http:\/\/www.xavignu.com\/wp-content\/uploads\/2018\/05\/GPS2.jpg\"><img loading=\"lazy\" src=\"http:\/\/www.xavignu.com\/wp-content\/uploads\/2018\/05\/GPS2.jpg\" alt=\"\" width=\"1024\" height=\"768\" class=\"aligncenter size-full wp-image-1521\" srcset=\"https:\/\/www.xavignu.com\/wp-content\/uploads\/2018\/05\/GPS2.jpg 1024w, https:\/\/www.xavignu.com\/wp-content\/uploads\/2018\/05\/GPS2-300x225.jpg 300w, https:\/\/www.xavignu.com\/wp-content\/uploads\/2018\/05\/GPS2-768x576.jpg 768w, https:\/\/www.xavignu.com\/wp-content\/uploads\/2018\/05\/GPS2-624x468.jpg 624w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><br \/>\nAnother important thing is to cross TxD and RxD cables, that means connecting GPS TxD to Orange Pi RxD and GPS RxD to Orange Pi TxD.<br \/>\nNow that the GPS module is connected to the Orange Pi power it up and log into it. We will now check if the GPS mocule is working, in order to do this we will connect via minicom.<\/p>\n<pre id=\"terminal\">minicom -D \/dev\/ttyS2 -b 9600\r\nWelcome to minicom 2.7\r\n\r\nOPTIONS: I18n \r\nCompiled on Apr 26 2017, 00:45:18.\r\nPort \/dev\/ttyS2, 19:10:00\r\n\r\nPress CTRL-A Z for help on special keys\r\n\r\n$GPRMC,191013.00,A,4252.31265,N,7833.00897,W,0.180,,040518,,,A*64\r\n$GPVTG,,T,,M,0.180,N,0.333,K,A*29\r\n$GPGGA,191013.00,4252.31265,N,7833.00897,W,1,06,2.16,296.4,M,51.3,M,,*44\r\n$GPGSA,A,3,22,16,10,08,26,27,,,,,,,3.81,2.16,3.14*04\r\n$GPGSV,3,1,10,01,19,244,,08,60,313,24,10,49,079,28,16,36,164,36*74\r\n$GPGSV,3,2,10,18,42,250,22,20,07,038,,21,06,061,,22,09,195,30*7A\r\n$GPGSV,3,3,10,26,09,158,30,27,69,072,27*70\r\n$GPGLL,4252.31265,N,7833.7897,W,191013.00,A,A*7C\r\n<\/pre>\n<p><!--more--><\/p>\n<p>Output is pretty ugly as can be seen but you can see the coordinates in GPGLL entry. In order to have something more readable we install below packages.<\/p>\n<pre id=\"terminal\">sudo dpkg -l | grep -i gps\r\nii  gpsd                           3.11-3                           armhf        Global Positioning System - daemon\r\nii  gpsd-clients                   3.11-3                           armhf        Global Positioning System - clients\r\nii  libgps21:armhf                 3.11-3                           armhf        Global Positioning System - library\r\nii  python-gps                     3.11-3                           armhf        Global Positioning System - Python libraries\r\n<\/pre>\n<p>Now copy below script and execute in order to start gpsd and listen on ttyS2.<br \/>\n[bash]<br \/>\n#!\/bin\/bash <\/p>\n<p>sudo gpsd \/dev\/ttyS2 -F \/var\/run\/gpsd.sock<br \/>\n[\/bash]<br \/>\nNow I created below python script which prints creates Google Maps URL based on GPS coordinates.<br \/>\n[python]<br \/>\nimport gps<\/p>\n<p># Listen on port 2947 (gpsd) of localhost<br \/>\nsession = gps.gps(&#8220;localhost&#8221;, &#8220;2947&#8221;)<br \/>\nsession.stream(gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE)<\/p>\n<p>while True:<br \/>\n    try:<br \/>\n        report = session.next()<br \/>\n        # Wait for a &#8216;TPV&#8217; report and display current time<br \/>\n        if report[&#8216;class&#8217;] == &#8216;TPV&#8217;:<br \/>\n            if hasattr(report, &#8216;time&#8217;) and hasattr(report, &#8216;lat&#8217;) and hasattr(report, &#8216;lon&#8217;):<br \/>\n                print report.time<br \/>\n                print &#8220;Latitude: &#8220;+str(report.lat)+&#8221;, Longitude: &#8220;+str(report.lon)<br \/>\n                print &#8220;Google Maps URL: https:\/\/maps.google.com\/?q=&#8221;+str(report.lat)+&#8221;,&#8221;+str(report.lon)+&#8221;\\n&#8221;<br \/>\n    except KeyError:<br \/>\n        pass<br \/>\n    except KeyboardInterrupt:<br \/>\n        quit()<br \/>\n    except StopIteration:<br \/>\n        session = None<br \/>\n        print &#8220;GPSD has terminated&#8221;<\/p>\n<p>[\/python]<br \/>\nAnd we proceed executing.<\/p>\n<pre id=\"terminal\">python gps.py \r\n2018-05-04T19:40:02.000Z\r\nLatitude: 42.872081491, Longitude: -78.549973218\r\nGoogle Maps URL: https:\/\/maps.google.com\/?q=42.872081491,-78.549973218\r\n\r\n2018-05-04T19:40:03.000Z\r\nLatitude: 42.872081044, Longitude: -78.549972807\r\nGoogle Maps URL: https:\/\/maps.google.com\/?q=42.872081044,-78.549972807\r\n\r\n2018-05-04T19:40:04.000Z\r\nLatitude: 42.872081426, Longitude: -78.549970823\r\nGoogle Maps URL: https:\/\/maps.google.com\/?q=42.872081426,-78.549970823\r\n\r\n2018-05-04T19:40:05.000Z\r\nLatitude: 42.872081634, Longitude: -78.549968307\r\nGoogle Maps URL: https:\/\/maps.google.com\/?q=42.872081634,-78.549968307\r\n\r\n2018-05-04T19:40:06.000Z\r\nLatitude: 42.872082718, Longitude: -78.549965683\r\nGoogle Maps URL: https:\/\/maps.google.com\/?q=42.872082718,-78.549965683\r\n<\/pre>\n<p>And opening the URL on Google Maps.<br \/>\n<iframe loading=\"lazy\" src=\"https:\/\/www.google.com\/maps\/embed?pb=!1m18!1m12!1m3!1d2994212.9425027254!2d-80.79117667020321!3d42.87208267915577!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x0%3A0x0!2zNDLCsDUyJzE5LjUiTiA3OMKwMzInNTkuOSJX!5e0!3m2!1sen!2ses!4v1525464161670\" width=\"600\" height=\"450\" frameborder=\"0\" style=\"border:0\" allowfullscreen><\/iframe><br \/>\nThanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently I got myself a GPS module to play with such as this. Not that I knew much about but felt like something nice to play with. First thing first is connecting the GPS module to the GPIO in Orange Pi 2G. In my case I decided to connect the GPS to ttyS2, asides from [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[92],"tags":[56,22,95,6,93,94,67],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/pTQgt-oq","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/posts\/1514"}],"collection":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1514"}],"version-history":[{"count":17,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/posts\/1514\/revisions"}],"predecessor-version":[{"id":1551,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/posts\/1514\/revisions\/1551"}],"wp:attachment":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1514"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1514"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1514"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}