2

I am currently trying to write a python (2.7) script based around the GPSd library to provide GPS speed data at an update rate of 10Hz using the adafruit Ultimate GPS raspberry Pi Hat (https://www.adafruit.com/product/2324) with time stamps also reported at 0.1s.

The module itself is capable of up to 10Hz update rates however defaults to 1 Hz when set up and currently I cannot successfully increase it. I've have tried issuing PMTK commands (https://cdn-shop.adafruit.com/datasheets/PMTK_A11.pdf) to increase the update rate however cannot get this to work (PMTK220) and have included setting the baudrate to the maximum value of 115200.

I've searched all over for a method of getting the update rate output to increase however cannot see where the issue lies. The code below and prints out responses at a rate faster than 10 Hz however the values are only being updated every 1s.

import os
import serial
from gps import *
import datetime
import time
import threading
import subprocess

#### CURRENTLY TRYING TO INCREASE GPS POLLING UPDATE RATE FROM DEFAULT 1Hz to 10Hz

subprocess.call(["stty","-F","/dev/serial0","raw","115200","cs8","clocal","-cstopb"])
subprocess.call(["sudo","systemctl","stop","gpsd.socket"])
subprocess.call(["sudo","systemctl","disable","gpsd.socket"])
subprocess.call(["sudo","gpsd","/dev/ttyS0","-F","/var/run/gpsd.sock"])

subprocess.call(["echo","-e","$PMTK251,115200*27\r\n","/dev/ttyS0"]) # command to set baudrate of serial port
subprocess.call(["echo","-e","$PMTK220,100*2F\r\n","/dev/ttyS0"]) #command to set GPS Update Rate

gpsd = None #seting the global variable

os.system('clear') #clear the terminal (optional)

class GpsPoller(threading.Thread):
  def __init__(self):
    threading.Thread.__init__(self)
    global gpsd #bring it in scope
    gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info
    self.current_value = None
   self.running = True #setting the thread running to true

  def run(self):
    global gpsd
    while gpsp.running:
      gpsd.next() #this will continue to loop and grab EACH set of gpsd info to clear the buffer

gpsp = GpsPoller() # create the thread
gpsp.start() # start it up
os.system('clear')

x = 0
while x < 20: # infinite loop- use ctrl + c to end
    print gpsd.utc # print timestamp
    print gpsd.fix.speed # print gps speed
    print '-----------------'
    time.sleep(0.025) # Set print rate much higher than maximum possible of 10 Hz update rate

GPS script output

1 Answers1

2

Probably a little late for this, but the module is set to a 9600 rate by default, iirc. Try setting the baud to 9600 on the Pi first then send the $PMTK251,115200 line. Now change the rate on the Pi to 115200 & send the 10hz part ($PMTK220,100*2F\r\n)

FoxGT58
  • 21
  • 2