How to Use NEO 6M GPS with RPI (Begginer Friendly)

Today you will learn how to use the Neo 6m GPS module with the raspberry pi. Now you can create your own GPS service to use on your travels.

Parts Required

  • Raspberry Pi
  • NEO 6M GPS Module
  • Male to male jumper wires
  • Breadboard

(If this is your first time using the raspberry pi and you want to learn how to ssh access you can do it: here.)

So let’s start with the connections:

Through this connection, the raspberry can receive information from the GPS module and can also supply it with power.

To configure the microcontroller you will need to execute the following code:

sudo nano /boot/config.txt

At the bottom of the file you will add the following configs (copy exactly as written here):


Now you just have to press ctrl+x and y to return to the command line.

RaspberryOS uses UART (universal asynchronous receiver-transmitter). To work with the GPS module we have to change this default characteristic.

To change it, execute the following code on the command line:

sudo nano /boot/cmdline.txt

And replace the code with the following code:

dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait quiet splash plymouth.ignore-serial-consoles

Now you just have to save with the journey: ctrl+x and y (don’t forget this keyboard combination that you will use a lot).

To apply the changes, let’s reboot:

sudo reboot

(Sudo will run commands with elevated privileges. It allows you to became a superuser).

After the reboot, our GPS should start working.

To understand if the GPS module is working, you should see the red light blinking!
It is important that you are in a place with a GPS range (ideally outdoors or very close to the window).
Depending on the source of the module, it may take up to 6/8min to receive GPS Data.

When it gets the light blinks, go to the raspberry’s command line again and run the following code:

sudo cat /dev/ttyAMA0

Now your screen will look like the matrix movie intro, with several lines similar to this one:

GPS signal in the command line.

(Before you continue, check if there are too many empty spaces on the lines. Each space corresponds to data received from different satellites.

If most of them are missing, it means that you don’t have good GPS coverage in the current space. Move for an outdoor space for the first setup).

We will have to make a new configuration now.

Originally, raspberry uses a serial port for this “login console” If we want to use the serial port to receive GPS data, we need to disable the login console.

There are 2 serial ports on the raspberry: 1 and 0.

Now let’s use the following code to see where the serial0 port is on your raspberry.

ls -l /dev

If the result is this:

crw-rw-r-- 1 root netdev 20, 38 Jul 10 12:00 rfkill
lrwxrwxrwx 1 root root 7 Jul 10 12:01 serial0 -> ttyAM0
lrwxrwxrwx 1 root root 7 Jul 10 12:01 serial1 -> ttyS0

Your serial0 is linked with ttyAMA0. To disable this port you will need to use the following command:

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

If your output is this:

crw-rw-r-- 1 root netdev 20, 38 Jul 10 12:00 rfkill
lrwxrwxrwx 1 root root 7 Jul 10 12:01 serial0 -> ttyS0
lrwxrwxrwx 1 root root 7 Jul 10 12:01 serial1 -> ttyAM0

This already means that serial0 is linked to ttyS0. You need the code:

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

The configuration is done, let’s move on to the program.

Python To Decode GPS

To get started you will need the pynmea2 library.

This library is responsible for parsing and is compatible with python 2.7 and python 3.3 (library link:

Now that you have the library you need, you are ready to start programming.

To do this you will use the following command:

sudo nano

Then you paste the following code inside:

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)

Now you run the program through:

sudo python

If everything is going as expected, you should have a latitude value and a longitude value.

From here you are ready to develop any script with your GPS location!

In the next tutorial, we will look at a practical application with a distance counter.


[1] –

[2] –

[3] –

Leave a Reply

Your email address will not be published. Required fields are marked *

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
Best Wordpress Adblock Detecting Plugin | CHP Adblock