GPS plays a prominent role in the present day navigation systems, starting out with smartphones and automobiles to much complex missile guidance systems. Yes!! the GPS is indispensable. That was, just to remind ourselves the importance of GPS and to understand how painstaking the navigation, without GPS, will be; plotting a course, getting lost, and finally finding the way.
Actual topic here, as the title says, is communication between the Pi and a GPS module and there by reading the latitude and longitude. This quick learning guide will be helpful to add position tracking to your Pi project. So lets start on the topic here.
Raspberry Pi, interfaced with a GPS module, can be used for developing an advanced real-time navigation system. Incorporating the Pi’s image processing, audio processing and web interface capabilities along with the GPS data we can develop advanced navigation schemes for real-time implementation.
GPS module has four connection pins, namely: Vcc, GND, TX and RX. It requires a power input 5V 100mA ,which can be provided using any suitable supply source. The RX pin of Pi, i.e the 10th GPIO pin on the RPi board, should be connected to the TX pin of the GPS module. The GND pin of the GPS module and the GND pin of the RPi board (6th pin) should be grounded properly.
Once the connection are made and the modules are powered, make sure that the GPS module is kept in a place where the GPS has a clear view to the sky or at least near a window for reliable signal integrity. We may find problem receiving signals in indoor area, the GPS signal can get blocked by metal, deep forest, mountains etc.
Now open the python editor and program your Pi, to receive the serial data from the GPS module. A sample code is given below, which can be used as it is or you can modify it to suit your project.
import RPi.GPIO as GPIO
import os, time
from decimal import *
delay = 1
def find(str, ch):
for i, ltr in enumerate(str):
if ltr == ch:
port = serial.Serial("/dev/ttyAMA0", baudrate=9600, timeout=1)
while cd <= 50:
while ck <= 50:
rcv = port.read(10)
if '$GPRMC' in fd:
if dif > 50:
Using this GPS data we can pinpoint the corresponding location on Google maps. If you are using ‘midori’ web browser, then the code given below can be used to locate the coordinates.
The latitude and longitude values, received from the GPS module, should be concatenated with the address link. An example is shown below.
The ‘call‘ function is used to run terminal commands using Python. To import the call function add the following code at the beginning of your program.
from subprocess import call
We can also get the location address using the GPS data. The following link gives the location address for corresponding GPS data
Open up this link on your browser, using the ‘call‘ function, and you will get the location address.
Shop With Us
- Click here to buy Raspberry Pi 2 from RhydoLabz.
- Click here to buy Raspberry Pi 2 Starter Kit from RhydoLabz.
- Click here to buy Raspberry Accessories from RhydoLabz.
- Click here to buy GPS Receiver with Antenna (5V TTL SERIAL) from RhydoLabz.