GPS Dongle Interfaced With Raspberry Pi
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.
Modules Needed
Connect the GPS module to any of the USB port in the Raspberry Pi.
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.
To check out more details on the GPS module, follow this link.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import serial from decimal import * def find(str, ch): for i, ltr in enumerate(str): if ltr == ch: yield i ser = serial.Serial('/dev/ttyUSB0', 9600,timeout=.5) cd=1 while cd <= 50: ck=0 fd='' while ck <= 5: rcv = ser.readline(50) fd=fd+rcv ck=ck+1 if '$GPRMC' in fd: ps=fd.find('$GPRMC') dif=len(fd)-ps if dif > 50: data=fd[ps:(ps+50)] print data ds=data.find('A') if ds > 0 and ds < 20: p=list(find(data, ",")) lat=data[(p[2]+1):p[3]] lon=data[(p[4]+1):p[5]] s1=lat[2:len(lat)] s1=Decimal(s1) s1=s1/60 s11=int(lat[0:2]) s1=s11+s1 s2=lon[3:len(lon)] s2=Decimal(s2) s2=s2/60 s22=int(lon[0:3]) s2=s22+s2 print s1 print s2 |
So thats the code to locate your Pi. Once the Pi is on with this code, it will receive the location coordinates from the GPS and the same can viewed in the Python Shell.
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.
call(“midori https://www.google.co.in/maps/@latitude,longitude“)
The latitude and longitude values, received from the GPS module, should be concatenated with the address link. An example is shown below.
call(“midori https://www.google.co.in/maps/@9.6385,77.0059”)
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
http://maps.google.com/maps/api/geocode/json?address=lattitude,longitude
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 Dongle from RhydoLabz
Leave a Reply
You must be logged in to post a comment.