In this video lesson I show how to get usable Latitude and Longitude from the Adafruit Ultimate GPS version 3 using the Raspberry Pi Pico W. We read the NMEA sentences from the GPS, we parse them into individual strings for each sentence, and then we create arrays of data from the strings. Then we begin to parse the arrays, and convert the confusing numbers into useful Decimal Degree values for Latitude and Longitude.

For your convenience, this is the code we developed in todays lesson:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | from machine import Pin,I2C,UART #*************** import time GPS = UART(1, baudrate=9600, tx=machine.Pin(8), rx=machine.Pin(9)) myNMEA="" GPGGA="" GPGSA="" GPRMC="" GPVTG="" GPGSV="" while not GPS.any(): pass while GPS.any(): junk=GPS.read() print(junk) try: while True: if GPS.any(): #myChar=GPS.read(1) myChar=GPS.read(1).decode('utf-8') myNMEA=myNMEA+myChar if myChar=='\n': if myNMEA[1:6]=="GPGGA": GPGGA=myNMEA GPGGAarray=GPGGA.split(',') #print(GPGGA) #print(GPGGAarray) if int(GPGGAarray[6]) != 0: latRAW=GPGGAarray[2] lonRAW=GPGGAarray[4] numSat=int(GPGGAarray[7]) latDD=int(latRAW[0:2])+float(latRAW[2:])/60 lonDD=int(lonRAW[0:3])+float(lonRAW[3:])/60 if GPGGAarray[3]=='S': latDD=-latDD if GPGGAarray[5]=='W': lonDD=-lonDD print("LAT, LON, numSat ",latDD,lonDD,numSat) if myNMEA[1:6]=="GPGSA": GPGSA=myNMEA GPGSAarray=GPGSA.split(',') if myNMEA[1:6]=="GPRMC": GPRMC=myNMEA GPRMCarray=GPRMC.split(',') knots=float(GPRMCarray[7]) heading=float(GPRMCarray[8]) print(knots, "Knots at a Heading of: ",heading) if myNMEA[1:6]=="GPVTG": GPVTG=myNMEA GPVTGarray=GPVTG.split(',') if myNMEA[1:6]=="GPGSV": GPGSV=myNMEA GPGSVarray=GPGSV.split(',') if GPGGA!="": if int(GPGGAarray[6])==0: print('Aquiring Fix:', GPGSVarray[3], "Sattellites in View") myNMEA="" except KeyboardInterrupt: print("\nStopping program... Cleaning up UART.") GPS.deinit() # Properly release UART before exit time.sleep(1) # Short pause to ensure clean shutdown print("Exited cleanly.") |