Hey Guys! You may have heard about “NMEA codes” with respect to GPS. In this project, we're interfacing U-blox NEO-6M GPS Module with Raspberry Pi and will decode the GPS data from NMEA codes.
An U-blox NEO-6M GPS Module has a battery for power backup and EEPROM for storing configuration settings. This GPS Module has 4 pins: VCC (Supply Voltage), GND (Ground), Tx (Transmitter), and Rx (Receiver).
This module provides nonstop NMEA (National Marine Electronics Association) data strings to the TX pin resulting in GPS information. To know more about this module, you can download its datasheet here.
Now, you got info. about the GPS module. So, let's get started with Raspberry Pi.
1. Connect Raspberry Pi with PCFirst of all, connect your Raspberry Pi Board with a PC. For PC connection info, please refer: https://www.raspberrypi.org/blog/getting-started-raspberry-pi/
For the information regarding the installation, visit this link: https://www.raspberrypi.org/documentation/installation/installing-images/
2. Interface GPS Module with Raspberry PiFor interfacing, make the connections as follows:
1)Connect Vcc of GPS module to Power Supply Pin No.2 (5V) of Raspberry Pi.
2)Connect Tx (Transmitter Pin) of GPS module to Pin No.10 of Raspberry Pi.
3)Connect GND (Ground Pin) of GPS module to Pin No.6 Raspberry.
3. Set Up the UART in Raspberry PiThe first thing we will do under this is to edit the /boot/config.txt file. To do this, run the commands below:
sudo nano /boot/config.txt
At the bottom of the config.txt file, add the following lines.
dtparam=spi=on
dtoverlay=pi3-disable-bt
core_freq=250
enable_uart=1
force_turbo=1
Press Ctrl+x to exit. Press y and enter to save.
The second step under this UART setup section is to edit the boot/cmdline.txt.
I will suggest you make a copy of the cmdline.txt and save first before editing so you can revert back to it later if needed. This can be done using following command.
sudo cp /boot/cmdline.txt /boot/cmdline_backup.txt
Now to edit that file open that in text editor.
sudo nano /boot/cmdline.txt
Replace the content with following command.
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles
Press Ctrl+x to exit and press y and enter to save. Now reboot pi using following command.
sudo reboot
4. Disable the Raspberry Pi Serial Getty Servicea. If in your output, Serial0 is linked with ttyAMA0, then to disable it use the below command.
sudosystemctl stop serial-getty@ttyAMA0.service
sudosystemctl disable serial-getty@ttyAMA0.service
b. If in your output Serial0 is linked with ttys0, then to disable it use the below command.
sudosystemctl stop serial-getty@ttyS0.service
sudosystemctl disable serial-getty@ttyS0.service
5. Install Minicom and Pynmea2Use minicom python library to connect with the GPS module and make sense of the data.
sudo apt-get install minicom
Use pynmea2 python library to parse the received NMEA data.
pip install pynmea2
6. Test OutputTo test the GPS, run the command.
sudo cat /dev/ttyAMA0
You'll get the output as shown.
All NMEA messages start with the $ character, and each data field is separated by a comma. $GNGGA is the basic NMEA message. It provides 3D location and accurate data.
7. Write Python CodesCode as below.
import serial
Import time
import string import pynmea2
while True: port=“/dev/ttyAMAO”
ser=serial.Serial(port,baudrate=9600,timeout=0.5)
dataout =pynmea2.NMEAStreamReader()
newdata=ser.readline()
if newdata[0:6]==“$GPRMC”:
newmsg=pynmea2.parse(newdata)
lat=newmsg.latitude
lng=newmsg.longitude
gps=“Latitude=" +str(lat) + “and Longitude=" +str(lng)
print(gps)
8. Final OutputIf you run this above python code, you will see a output like this.
Well, that's it! You've got your GPS data.
Hope, this project is helpful to you.
Reference: Interfacing of GPS Module with Arduino and Raspberry Pi- by Priyanka Dixit
Comments
Please log in or sign up to comment.