Interfacing GPS module with Raspberry Pi
Installation Manual
• GPS stands for Global Positioning System and used to detect the Latitude and Longitude of any
location on the Earth, with exact UTC time (Universal Time Coordinated).
• GPS module is the main component in our vehicle tracking system.
• This device receives the coordinates from the satellite for each and every second, with time and
date.
• GPS module sends the data related to tracking position in real time, and it sends so many data in
NMEA format.
• NMEA format consists of sentence starts from $GPGGA, the coordinates, time and other useful
information.
• GPGGA is referred to Global Positioning System Fix Data.
• GPGGA string contains following co-ordinates separated by commas.
Sr Sr
No Identifier Description No Identifier Description
Global Positioning system
1 $GPGGA 7 FQ Fix Quality Data
fix data
Time in hour minute
No. of Satellites being
2 HHMMSS.SSS seconds and milliseconds 8 NOS
Used
format.
Horizontal Dilution of
3 Latitude Latitude (Coordinate) 9 HPD
Precision
Direction N=North, Altitude from sea
4 N 10 Altitude
S=South level
5 Longitude Longitude(Coordinate) 11 M Meter
Direction E= East,
6 E 12 Height Height
W=West
13 Checksum Checksum Data
Hardware Requirements Software Requirements
• Raspberry Pi Model B/B+ , SD Card • Raspbian Stretch OS
• Ethernet Cable / Wi-Fi • Adafruit Python Char LCD Library
• Power Supply to Pi
• Neo 6m v2 GPS Module
• Jumper wires
• Breadboard
• 2x16 LCD Display
• Potentiometer (to adjust Contrast)
1|Page Manorama Darekar,Gurukul College.
Neo 6m v2 GPS Module
This board features the u-blox NEO-6M GPS module with
antenna and built-in EEPROM. This is compatible with
various flight controller boards designed to work with a GPS
module.
EEPROM is used for saving the configuration data when
powered off.
Power Supply Range: 3 V to 5 V
Default Baud Rate: 9600 bps
Connect GPS Module to RPi
Connection is very simple. Requires 4 Female to Female Jumper Wires
Neo 6m V2 GPS Raspberry Pi
Details Raspberry Pi Function
Board Pin Physical Pin
VCC Power Pin 1 3.3V Power
GND Common Ground Pin 39 GND
TXD Data Output Pin 10 (UART_RXD0) GPIO15
RXD Data Input Pin 8 (UART_TXD0) GPIO14
Connect 2x16 LCD Display to RPi
A 16x2 LCD is used for displaying all messages. A 10k Potentiometer is also used with LCD for
controlling the contrast. I used following GPIO pins to connect LCD to Raspberry Pi’s GPIO Pins:
Sr No LCD Display Board Pin RPI Physical Pin Raspberry Function
4 RS 37 GPIO26
6 E 35 GPIO19
11 D4 33 GPIO13
12 D5 31 GPIO6
13 D6 29 GPIO5
14 D7 23 GPIO11
2|Page Manorama Darekar,Gurukul College.
Connect GPS module to Raspberry Pi’s GPIO Pins by using Female to Female Jumper wires
Connect 2x16 LCD Display to Raspberry Pi’s GPIO Pins with the help of breadboard and
jumper wires.
Step 1: Update Raspberry Pi
Step 2: edit the /boot/config.txt file
At the bottom of this file, add the above lines
The dtoverlay=pi3-disable-bt disconnects the bluetooth from the ttyAMA0, this is to allow us access to
use the full UART power available via ttyAMAO instead of the mini UART ttyS0.
Save with Ctrl+X, yes and press Enter.
3|Page Manorama Darekar,Gurukul College.
Step 3: Before proceeding, make a copy of cmdline.txt file
Now, edit file cmdline.txt
Remove console=serial0,115200 and Modify root=/dev/mmcblk0p2
Save with Ctrl+X, yes and press Enter.
Step 4: Reboot Raspberry Pi using the command sudo reboot
Step 5: Stop and disable the Pi’s serial ttyS0 service
The following commands can be used to enable it again if needed
sudo systemctl enable serial-getty@ttyS0.service
sudo systemctl start serial-getty@ttyS0.service
Step 6: Reboot Raspberry Pi using the command sudo reboot
Step 7: Now, Enable the ttyAMA0 service
Verify it using ls –l /dev command
4|Page Manorama Darekar,Gurukul College.
Step 8: Install minicom and pynmea2
Install minicom package which is used to connect to the GPS module and make sense of the data.
Install pynmea2 library which is used to parse the received data.
Step 9: Use minicom command to test our GPS module is working fine.
9600 represents the baud rate at which the GPS module communicates.
Here, we can see NMEA sentences .NMEA format consist several sentences, in which we only need
one sentence. This sentence starts from $GPGGA and contains the coordinates
Sometimes we received sentences which contains unknown msg*58, but this is not an error, actually it
may takes some time to track your GPS module. (Even for the first time more than 20-30 minutes.)
I suggest keep your GPS module's antenna in open space (e.g. near the window)
To exit from above window, Press Ctrl+A, and Press x and Enter Key.
Step 10: The above same test can also be done using cat command
This sentence gives you Latitude found after two commas and Longitude found after four commas.
5|Page Manorama Darekar,Gurukul College.
Step 11: Write Python script to display your current Latitude and Longitude on LCD Display.
Python Script (gpsdemo.py)
import time
import serial
import string
import pynmea2
import RPi.GPIO as gpio
import Adafruit_CharLCD as LCD
gpio.setmode(gpio.BCM)
lcd = LCD.Adafruit_CharLCD(rs=26, en=19,
d4=13, d5=6, d6=5, d7=11,
cols=16, lines=2)
lcd.message("MSD Gurukul\n Welcomes You")
time.sleep(2)
lcd.clear()
lcd.message("GPS Demo")
time.sleep(2)
lcd.clear()
port = "/dev/ttyAMA0" # the serial port to which the pi is connected.
#create a serial object
ser = serial.Serial(port, baudrate = 9600, timeout = 0.5)
try:
while 1:
try:
data = ser.readline()
except:
print("loading")
#wait for the serial port to churn out data
if data[0:6] == '$GPGGA': # the long and lat data are always contained in the GPGGA string of
the NMEA data
msg = pynmea2.parse(data)
latval = msg.lat #parse the latitude and print
concatlat = "Lat:" + str(latval)
print(concatlat)
lcd.set_cursor(0,0)
lcd.message(concatlat)
6|Page Manorama Darekar,Gurukul College.
#parse the longitude and print
longval = msg.lon
concatlong = "Long:"+ str(longval)
print(concatlong)
lcd.set_cursor(0,1)
lcd.message(concatlong)
time.sleep(0.5)#wait a little before picking the next data.
except KeyboardInterrupt:
lcd.clear()
lcd.message("Thank You")
time.sleep(2)
Run Python script on terminal using sudo command (sudo gpsdemo.py)
That's all!!!
Thank you….
7|Page Manorama Darekar,Gurukul College.