In this video lesson we advance our project by using both cores on the Raspberry Pi Pico W. One core is used exclusively to read the GPS data coming over the UART bus. Then the other core can be used to parse the NMEA sentences, or for other purposes. We are using the following circuit schematic:

In this video, we developed the following code:
|
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# ==================================================================== # DISCLAIMER: # This code is provided as-is for educational and experimental # purposes only. The author makes no representations or warranties of # any kind concerning the safety, suitability, or accuracy of this # code. Use at your own risk. The author assumes no liability for any # damages, system failures, security breaches, or network issues # resulting from the use or implementation of this script. # ==================================================================== from machine import Pin,I2C,UART import time import _thread dataLock = _thread.allocate_lock() keepRunning = True GPS = UART(1, baudrate=9600, tx=machine.Pin(8), rx=machine.Pin(9)) # The following line ensures that the GPS reports the GPVTG NMEA Sentence GPS.write(b"$PMTK314,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0*28\r\n") NMEAdata = { 'GPGGA' : "", 'GPGSA' : "", 'GPRMC' : "", 'GPVTG' : "" } def gpsThread(): print("Thread Running") global keepRunning,NMEAdata GPGGA = "" GPGSA = "" GPRMC = "" GPVTG = "" while not GPS.any(): pass while GPS.any(): junk = GPS.read() print(junk) myNMEA = "" while keepRunning: if GPS.any(): myChar=GPS.read(1).decode('utf-8') myNMEA = myNMEA + myChar if myChar == '\n': myNMEA = myNMEA.strip() if myNMEA[1:6] == "GPGGA": GPGGA = myNMEA if myNMEA[1:6] == "GPGSA": GPGSA = myNMEA if myNMEA[1:6] == "GPRMC": GPRMC = myNMEA if myNMEA[1:6] == "GPVTG": GPVTG = myNMEA if GPGGA != "" and GPGSA!="" and GPRMC!="" and GPVTG!="": dataLock.acquire() NMEAdata = { 'GPGGA' : GPGGA, 'GPGSA' : GPGSA, 'GPRMC' : GPRMC, 'GPVTG' : GPVTG } dataLock.release() myNMEA = "" print("Thread Terminated Cleanly") _thread.start_new_thread(gpsThread,()) try: while True: dataLock.acquire() NMEAmain = NMEAdata.copy() dataLock.release() print(NMEAmain['GPGGA']) ts=10 time.sleep(ts) except KeyboardInterrupt: print("\nStopping Program . . . Cleaning Up UART") keepRunning = False ts=1 time.sleep(ts) GPS.deinit() time.sleep(ts) print("Exited Cleanly") |

