Python Forum
Python in Linux environment on RPI
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python in Linux environment on RPI
#21
(Sep-03-2020, 03:50 AM)Larz60+ Wrote: K_Research -- Please note that you are responding to a three+ year old thread,and doubtful OP will see, hasn't logged in since last January.

Well aware of the dates of this topic I added the info to help others in the future working on GPS projects, I found this thread doing a Google search for from gps import *

I am Python stupid and I am searching for code that will allow users to create a GPS Waypoint by pushing a button. I found Python code records a track to a .CSV file and that works well now I just need to create Waypoints.

I am running out of luck I suppose I should create a topic and post my current code and ask for suggestions?

Thanks
Reply
#22
yes, post the code. that and what you are expecting or wanting it to do. i don't know anything about GPS or Waypoints. maybe i will learn from your response.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#23
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.
#! /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()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is possible to run the python command to call python script on linux? cuten222 6 730 Jan-30-2024, 09:05 PM
Last Post: DeaD_EyE
  Installing python packages in a virtual environment Led_Zeppelin 1 764 Aug-15-2023, 08:18 PM
Last Post: deanhystad
  Understanding venv; How do I ensure my python script uses the environment every time? Calab 1 2,268 May-10-2023, 02:13 PM
Last Post: Calab
  Python development environment standenman 3 1,625 May-04-2023, 07:24 PM
Last Post: snippsat
  Python Scripting Environment jpotter0 1 1,713 Nov-19-2022, 03:07 PM
Last Post: snippsat
  How to use a variable in linux command in python code? ilknurg 2 1,601 Mar-14-2022, 07:21 AM
Last Post: ndc85430
  How do I link the virtual environment of that project to the 3.9.2 version of python? Bryant11 1 1,374 Feb-26-2022, 11:15 AM
Last Post: Larz60+
  Python syntax in Linux St0rmcr0w 2 51,360 Jul-29-2021, 01:40 PM
Last Post: snippsat
  VS Code debugger using wrong Python environment topfox 0 2,510 Jun-09-2021, 10:01 AM
Last Post: topfox
  Login to NordVPN on Linux with python script AGreenPig 2 5,994 Feb-09-2021, 10:44 AM
Last Post: AGreenPig

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020