How to Interface GPS Module with Raspberry Pi

GPS stands for Global Positioning System. GPS module find the location (latitude, longitude, altitude) by comparing the time taken for receiving signals from satellites in its vicinity. GPS offers a great accuracy and also provides other data besides position coordinates.

From smartphones and autos to considerably more advanced missile guidance systems, GPS plays a significant part in today’s navigation systems. Yes, the GPS is a must-have.

A Raspberry Pi with a GPS module can be used to create an advanced real-time navigation system. We can design complex navigation systems for real-time execution by combining the Pi’s image processing, voice processing, and web interface capabilities with GPS data. This article discusses how to interface the UBlox NEO-M8N global positioning system (GPS) module with Raspberry Pi

Hardware Required:

  • U-Blox NEO-M8N GPS module 
  • Raspberry Pi 
  • Breadboard
  • Connecting Wires

Global Positioning System

The GPS (Global Positioning System) is a satellite-based navigation system with at least 24 satellites. 

Global Positioning System (GPS) makes use of signals sent by satellites in space and ground stations on Earth to accurately determine their position on Earth. The GPS receives radio frequency signals from satellites and ground stations. These signals are used by GPS to identify their precise location. With no subscription fees or setup charges, GPS works in any weather condition, anywhere in the world, 24 hours a day.

How does GPS work?

GPS satellites circle the Earth twice a day in a precise orbit. Each satellite transmits a unique signal and orbital parameters that allow GPS devices to decode and compute the precise location of the satellite.This information, together with trilateration, is used by GPS receivers to calculate a user’s actual location. The GPS receiver calculates the distance between each satellite by the time it takes to receive a broadcast signal. The receiver can determine and show a user’s position using distance measurements from a few more satellites.

A GPS receiver must be locked on to the signal of at least three satellites to determine your 2-D position (latitude and longitude) and track movement. The receiver can calculate your 3-D position if there are four or more satellites in view (latitude, longitude, and altitude). A GPS receiver will often track eight or more satellites, depending on the time of day and where you are on the planet.

After determining your location, the GPS unit can calculate additional data, such as:

  • Speed
  • Bearing
  • Track
  • Trip dist
  • Distance to destination

The Raspberry Pi GPS module is a simple electronic circuit that connects to your Arduino board to provide position, altitude, speed, date, and time in UTC (Universal Time Coordinated). It transmits position data via the serial port using the standard NMEA protocol (

 U-Blox NEO-M8N GPS module 

This popular NEO-M8N is designed as a high Precision GPS Module. It comes with a Built-in Compass HMC5883L digital compass for APM and pixhawk. This module provides a high level of sensitivity and features active circuitry for the ceramic patch antenna. It is enclosed in a plastic case to protect the module from the elements. Also, the module outputs offer precise position updates at 10Hz and also have a rechargeable backup battery for warm starts. The Ublox NEO-M8N is configured to run at a baud rate of 38400 and can be used with Pixhawk and APM. Moreover, this popular neo-M8N is capable of connecting the same module to All versions of the PIXHAWK Flight Controller. This was performed just after swapping its 5-pin connector with an extra 6-pin connector provided in the Package.

This new generation GPS NEO-M8N Offers a wide range of applications in GPS telemetry for your FPV flying or camera ship.  It is capable of providing an accuracy between 0.6 and 0.9 meters which is a significant improvement over previous models. Moreover, Satellite searching and acquisition is quite fast, generally taking around ten seconds to locate and acquire up to 6 satellites.  It also has a built-in compass with a 10Ghz refresh rate and a low noise figure which ensures this GPS module offers excellent performance.

The NEO-M8N features better performance and the easiest RF integration of all the NEO-M8 configurations. The NEO form factor allows for easy migration from previous NEO generations. Hence, the Sophisticated RF architecture and interference suppression ensure maximum performance even in GNSS-hostile environments. NEO-M8 combines a high level of robustness and integration capability with flexible connectivity options. Finally, the future-proof NEO-M8N consists of an internal Flash that allows simple firmware upgrades for supporting additional GNSS systems.

Features of U-Blox NEO-M8N GPS module 

  • The ceramic antenna provides a very strong signal
  • With LED indicator lamp
  • The default baud rate: is 9600.
  • With data backup battery.
  • LED signal indicator.
  • Compatible with various flight controller modules.
  • EEPROM saves the configuration parameter data when power-down.
  • Assistance AssistNow GNSS Online
  • AssistNow GNSS Offline (up to 35 days)
  • AssistNow Autonomous (up to 6 days)
  • OMA SUPL & 3GPP compliant
  • Oscillator TCXO
  • Built-in RTC crystal
  • Anti-jamming Active CW detection and removal.
  • Extra onboard SAW bandpass filter
  • Memory Flash
  • Supported antennas Active and passive
  • Odometer Travelled distance
  • Data-logger For position, velocity, and time

GPS Interfacing with Raspberry Pi:

To retrieve GPS data, connect the U-Blox NEO-M8N GPS module to the Raspberry Pi. To connect the GPS module to the Raspberry Pi, we used Python code.

Connection diagram:

Download the Raspbian Operating system and install it in the memory card through Balena Etcher software.

Step 1: Setting up the UART in Raspberry Pi

sudo nano /boot/config.txt
  • At the bottom of the file, add the below lines,

  • Now, Press ctrl+x to exit and press y and enter to save.

Because Raspbian uses the UART as a serial console, we’ll need to disable it. We need to make a change to the /boot/cmdline.txt file to accomplish this. Make a backup of the file using the following command for safety reasons before modifying it.

sudo cp boot/cmdline.txt boot/cmdline_backup.txtsudo nano /boot.cmdline.txt

  • Replace the content with the below line, 

  • Press ctrl+x to exit and press y and enter to save.

Now reboot pi to see the changes,

sudo reboot

Now we’ll see how our GPS module works.

Make sure the yellow LED on the Neo 8M is blinking before proceeding. Basically, the yellow LED blinking indicates that the GPS module is receiving data correctly. Run the following command when the Yellow LED is blinking. Serial0 and serial1 are the two serial ports of the Raspberry Pi 3. Because serial0 will point to GPIO pins 14 and 15, we’ve utilised it here. Now run the command below to see if the port is connected to serial0.

ls -l /dev

Step 2: Disabling the Raspberry Pi Serial Getty Service

After that, there are two possible outputs,

a.If Serial0 is associated with ttyAMA0 in your output, execute the command below to disable it.

sudo systemctl stop serial-getty@ttyAMA0.service
sudo systemctl disable serial-getty@ttyAMA0.service

b. If in your output Serial0 is linked with ttys0, then to disable it use the below command,

sudo systemctl stop serial-getty@ttys0.servicesudo systemctl disable serial-getty@ttys0.service

Now, again reboot the system using sudo reboot.

Step 3: Activating ttys0

We’ve disabled the ttyAMA0 in our system; the next step is to enable the ttyso.

sudo systemctl enable serial-getty@ttys0.service

Step 4: Install Minicom and pynmea2

To connect to the GPS module and make sense of the data, use the minicom python package.

sudo apt-get install minicom

To parse the received NMEA data, use the pynmea2 Python module.

sudo pip install pynmea2

Step 5: Testing output

Run the command below to test the GPS. The data transmission between the GPS Module and the Raspberry Pi microcontroller is shown in the graph below.

sudo cat /dev/ttyAMA0

Now, finally, we will write the python code for interfacing of the GPS module with Raspberry pi.

import serial

import time import string 
import pynmea2  while True: 

ser=serial.Serial(port, baudrate=9600, timeout=0.5) 
dataout =pynmea2.NMEAStreamReader() 
if newdata[0:6] == “$GPRMC”:  
gps = “Latitude=” + str(lat) + “and Longitude=” +str(lng) 

And here is the final result. It gives you information about your precise location in terms of latitude and longitude.

I hope all of you are clear about how to interface the GPS Module with Raspberry Pi.We MATHA ELECTRONICS will be back soon with more interesting topics.

Leave a Reply

Your email address will not be published.