Install Ublox M8N GPS on Raspberry pi/Nvidia Nano

Spread the love
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

References

https://ozzmaker.com/berrygps-setup-guide-raspberry-pi/

https://www.jetsonhacks.com/2019/10/10/jetson-nano-uart/

https://www.element14.com/community/community/designcenter/single-board-computers/blog/2019/05/21/nvidia-jetson-nano-developer-kit-pinout-and-diagrams

Application

Nvidia Nano

Raspberry Pi3B+

Ublox M8N GPS

Pinout

Image result for raspberry pi 3b+ pinout
GPSRaspberry Pi/Nano
VCCPin 2, 5V
GNDPin 6, GND
RxPin 8, UART Tx
TxPin 10, UART Rx
SDANot connected.
SCL Not connected.

Check GPS connection is working

If you have powered the GPS correctly a red led should be on.

This is a GPS, it needs to be able to see the sky to read satellites. you will need to move your GPS receiver near a window or outside so it can see the sky.

When the GPS is receiving data from satellites, four green led’s will blink.

Allow Raspberry Pi to access Serial

Go into the Raspberry pi settings and ‘enable‘ the serial and ‘disable‘ login from shell.

sudo raspi-config

Exit the config by choosing ‘Finish’. You will need to reboot.

sudo reboot

Allow Nvidia Nano to access Serial

From the command line enter the following.

systemctl stop nvgetty
systemctl disable nvgetty
udevadm trigger

Now reboot for the changes to take affect.

sudo reboot

Check GPS data is being received

From terminal, enter the following command to find available serial data.

dmesg | grep tty

For the Raspberry Pi the port we need is ‘ttyS0’. For the Nvidia Nano use ‘ttyTHS1’.

In terminal enter the following to read the data being received.

sudo cat /dev/ttyS0
sudo cat /dev/ttyTHS1

Alternatively, ttyS0 is also serial0 for the Raspberry Pi.

sudo cat /dev/serial0

You should see data scrolling on the screen. If your GPS is receiving data from satellites, a light will flash on your GPS. By default, you will receive basic data, but you will receive GPS data when the GPS lights are flashing.

Install GPS Apps

 sudo apt-get install gpsd-clients gpsd -y

Set gpsd to run in the background.

Change the gpsd files to read the GPS data.

sudo nano /etc/default/gpsd

In the file above look for:
DEVICES=””
and change it to
DEVICES=”/dev/serial0″

Press “Ctrl + X” to save and exit then follow the prompts.

Test your gps is installed

 systemctl | grep gpsd

Run GPS apps

Warning: These apps ONLY provide data if they’re receiving data from the GPS. If the sky is too cloudy or your GPS signal does not have a line of sight to the sky, these programs will not work.

gpsmon
cgps
gpspipe -r

GPS python3 code

Version 1.

import os

aa = 0

while True:

    aa += 1

    try:
        data = os.system("cat /dev/ttyS0")
    except KeyboardInterrupt:
        break

    print(aa)
    print(data)

Version 2

import serial               #import serial pacakge
#import time
#import webbrowser           #import package for opening link in browser
#import sys                  #import system package

'''
sudo python3 gpsdata2.py
'''

def GPS_Info():
    global NMEA_buff
    global lat_in_degrees
    global long_in_degrees
    nmea_time = []
    nmea_latitude = []
    nmea_longitude = []
    nmea_time = NMEA_buff[0]                    #extract time from GPGGA string
    nmea_latitude = NMEA_buff[1]                #extract latitude from GPGGA string
    nmea_longitude = NMEA_buff[3]               #extract longitude from GPGGA string

    print("NMEA Time: ", nmea_time,'\n')
    print("NMEA Latitude:", nmea_latitude,"NMEA Longitude:", nmea_longitude,'\n')

    lat = float(nmea_latitude)                  #convert string into float for calculation
    longi = float(nmea_longitude)               #convertr string into float for calculation

    lat_in_degrees = convert_to_degrees(lat)    #get latitude in degree decimal format
    long_in_degrees = convert_to_degrees(longi) #get longitude in degree decimal format

#convert raw NMEA string into degree decimal format   
def convert_to_degrees(raw_value):
    decimal_value = raw_value/100.00
    degrees = int(decimal_value)
    mm_mmmm = (decimal_value - int(decimal_value))/0.6
    position = degrees + mm_mmmm
    position = "%.4f" %(position)
    return position

gpgga_info = "$GPGGA,"
#ser = serial.Serial("/dev/ttyS0", baudrate = 9600)              #Open port with baud rate
ser = serial.Serial("/dev/ttyS0", baudrate = 57600)              #Open port with baud rate
GPGGA_buffer = 0
NMEA_buff = 0
lat_in_degrees = 0
long_in_degrees = 0

aa = 0

#print("lat in degrees:", lat_in_degrees," long in degree: ", long_in_degrees, '\n')
while (True):

    aa += 1
    print(aa)

    try:
        #received_data = str(ser.readline()) #read NMEA string received
        received_data = ser.readline() #read NMEA string received

        #print(received_data)
        #GPGGA_data_available = received_data.find(gpgga_info)  #check for NMEA GPGGA string

        '''
        if (GPGGA_data_available>0):
            #print('hello 5')
            GPGGA_buffer = received_data.split("$GPGGA,",1)[1]  #store data coming after "$GPGGA," string
            NMEA_buff = (GPGGA_buffer.split(','))               #store comma separated data in buffer
            GPS_Info()                                          #get time, latitude, longitude

            print("lat in degrees:", lat_in_degrees," long in degree: ", long_in_degrees, '\n')
            map_link = 'http://maps.google.com/?q=' + lat_in_degrees + ',' + long_in_degrees    #create link to plot location on Google map
            print("<<<<<<<<press ctrl+c to plot location on google maps>>>>>>\n")               #press ctrl+c to plot on map and exit
            print("------------------------------------------------------------\n")
        '''

    except KeyboardInterrupt:
        #webbrowser.open(map_link)        #open current position information in google map
        break

    if received_data != None:
        print(received_data)

Did it work for you?

If this didn’t work, please message us.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.