Sep-05-2020, 03:04 AM
(This post was last modified: Sep-05-2020, 03:04 AM by K_Research.)
I have a Raspberry Pi GPS project I am working on, the goal is to record GPS Tracks and to create Waypoints with the push of a button, so far I have the recording Tracks working, no luck on creating Waypoints.
I saved the below Python code to a folder on my Desktop/GPS I navigate to that folder in Terminal by typing cd Desktop/GPS hit enter then type python3 savetrack.py hit enter again.
If your getting a GPS signal you will see your location data start streaming at the same time if you open file manager and navigate to /home/pi/Desktop/GPS you will see a file named something like 20200904-000000_GSPData.csv basically its the date and time the file was created followed by GSPData.csv (look at line 9 of the code you can edit the filename) Use CTRL + Z in Terminal to stop recording the GPS data.
To finish this project I need to start and stop recording Tracks and Waypoints by pushing buttons, either with Touch Screen or by mechanical buttons.
Note: all the ### is my edits or entries, I included a link to the author of the code.
Suggestions, comments, questions? Thanks in advance.
The code.
I saved the below Python code to a folder on my Desktop/GPS I navigate to that folder in Terminal by typing cd Desktop/GPS hit enter then type python3 savetrack.py hit enter again.
If your getting a GPS signal you will see your location data start streaming at the same time if you open file manager and navigate to /home/pi/Desktop/GPS you will see a file named something like 20200904-000000_GSPData.csv basically its the date and time the file was created followed by GSPData.csv (look at line 9 of the code you can edit the filename) Use CTRL + Z in Terminal to stop recording the GPS data.
To finish this project I need to start and stop recording Tracks and Waypoints by pushing buttons, either with Touch Screen or by mechanical buttons.
Note: all the ### is my edits or entries, I included a link to the author of the code.
Suggestions, comments, questions? Thanks in advance.
The code.
#! /usr/bin/python ###How to save GPS data to a file using Python ### https://ozzmaker.com/how-to-save-gps-data-to-a-file-using-python/ ###Saves a new GPS data file in CSV format each time program is stopped in the directory savetrack.py is located from gps import * import time, inspect f = open(time.strftime("%Y%m%d-%H%M%S")+'_GSPData.csv','w') ###You can change the CSV file name here gpsd = gps(mode=WATCH_ENABLE|WATCH_NEWSTYLE) print ('GPStime utc\t\t\tlatitude\tlongitude\tspeed\tsats in view') # '\t' = TAB to try and output the data in columns. f.write("GPStime utc,latitude,longitude,speed,sats in view\n") try: while True: report = gpsd.next() # if report['class'] == 'TPV': GPStime = str(getattr(report,'time','')) lat = str(getattr(report,'lat',0.0)) lon = str(getattr(report,'lon',0.0)) speed = str(getattr(report,'speed','nan')) sats = str(len(gpsd.satellites)) print (GPStime,"\t",) print (lat,"\t",) print (lon,"\t",) print (speed,"\t",) print (sats,"\t") f.write(GPStime + ',' + lat +',' + lon + ',' + speed + ',' + sats + '\n') time.sleep(1) except (KeyboardInterrupt, SystemExit): #when you press ctrl+c print ("Done.\nExiting.") f.close()