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 VCC (2.8V) and GND. This correspond to pins 1, 6, 8 and 10.
Vcc -> pin 1
GND -> pin 6
TxD -> pin 8
RxD -> pin 10
Pin 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.
Another 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.
Now 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.
Welcome to minicom 2.7
Compiled on Apr 26 2017, 00:45:18.
Port /dev/ttyS2, 19:10:00
Press CTRL-A Z for help on special keys
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.
ii gpsd 3.11-3 armhf Global Positioning System - daemon
ii gpsd-clients 3.11-3 armhf Global Positioning System - clients
ii libgps21:armhf 3.11-3 armhf Global Positioning System - library
ii python-gps 3.11-3 armhf Global Positioning System - Python libraries
Now copy below script and execute in order to start gpsd and listen on ttyS2.
#!/bin/bash sudo gpsd /dev/ttyS2 -F /var/run/gpsd.sock
Now I created below python script which prints creates Google Maps URL based on GPS coordinates.
import gps # Listen on port 2947 (gpsd) of localhost session = gps.gps("localhost", "2947") session.stream(gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE) while True: try: report = session.next() # Wait for a 'TPV' report and display current time if report['class'] == 'TPV': if hasattr(report, 'time') and hasattr(report, 'lat') and hasattr(report, 'lon'): print report.time print "Latitude: "+str(report.lat)+", Longitude: "+str(report.lon) print "Google Maps URL: https://maps.google.com/?q="+str(report.lat)+","+str(report.lon)+"\n" except KeyError: pass except KeyboardInterrupt: quit() except StopIteration: session = None print "GPSD has terminated"
And we proceed executing.
Latitude: 42.872081491, Longitude: -78.549973218
Google Maps URL: https://maps.google.com/?q=42.872081491,-78.549973218
Latitude: 42.872081044, Longitude: -78.549972807
Google Maps URL: https://maps.google.com/?q=42.872081044,-78.549972807
Latitude: 42.872081426, Longitude: -78.549970823
Google Maps URL: https://maps.google.com/?q=42.872081426,-78.549970823
Latitude: 42.872081634, Longitude: -78.549968307
Google Maps URL: https://maps.google.com/?q=42.872081634,-78.549968307
Latitude: 42.872082718, Longitude: -78.549965683
Google Maps URL: https://maps.google.com/?q=42.872082718,-78.549965683
And opening the URL on Google Maps.
Thanks for reading.