Get data from GPS module at 10Hz in Python

GPS 10Hz with serial connection without using gpsd. The code is as follows, and write the code to process the received data in the main part at the bottom.

mtk3339_set_10Hz.py


#!/usr/bin/python3
# -*- coding: utf-8 -*-

from time import sleep
import serial

#Serial connection baudrate initial value:9600
ser=serial.Serial('/dev/ttyS0', baudrate=9600, timeout=30)

class GPS: 
    def __init__(self):
        UPDATE_100msec=  r"$PMTK220,100*2F\r\n"        #Update interval 100msec(10Hz)
        UPDATE_200msec=  r"$PMTK220,200*2C\r\n"        #Update interval 200msec(5Hz)
        UPDATE_250msec=  r"$PMTK220,250*29\r\n"        #Update interval 250msec(4Hz)
        UPDATE_500msec=  r"$PMTK220,500*2B\r\n"        #Update interval 500msec(2Hz)
        UPDATE_1000msec=  r"$PMTK220,1000*1F\r\n"      #Update interval 1sec(1Hz)
        MEAS_100msec= r"$PMTK300,100,0,0,0,0*2C\r\n"   #Measurement interval 100msec(10Hz)
        MEAS_200msec= r"$PMTK300,200,0,0,0,0*2F\r\n"   #Measurement interval 200msec(5Hz)
        MEAS_250msec= r"$PMTK300,250,0,0,0,0*2A\r\n"   #Measurement interval 250 msec(4Hz)
        MEAS_500msec= r"$PMTK300,500,0,0,0,0*28\r\n"   #Measurement interval 500msec(2Hz)
        MEAS_1000msec= r"$PMTK300,1000,0,0,0,0*1C\r\n" #Measurement interval 1 sec(1Hz)
        BAUDRATE_9600 = r"$PMTK251,9600*17\r\n"        #tty baud rate 9600bps
        BAUDRATE_19200 = r"$PMTK251,19200*22\r\n"      #tty baud rate 19200bps
        BAUDRATE_38400 = r"$PMTK251,38400*27\r\n"      #tty baud rate 38400bps
        BAUDRATE_57600 = r"$PMTK251,57600*2C\r\n"      #tty baud rate 57600bps
        BAUDRATE_115200 = r"$PMTK251,115200*1F\r\n"    #tty baud rate 115200bps

        #Commands for which NMEA Sentences are sent
        GPRMC_ONLY= "$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29\r\n" # Send only the GPRMC Sentence
        GPRMC_GPGGA="$PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28\r\n" # Send GPRMC AND GPGGA Sentences
        SEND_ALL ="$PMTK314,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0*28\r\n"  # Send All Sentences
        SEND_NOTHING="$PMTK314,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28\r\n" # Send Nothing

        ser.write(BAUDRATE_115200.encode('utf-8')) # Set Baudrate to 115200
        sleep(1)
        ser.baudrate=115200
        ser.write(UPDATE_100msec.encode('utf-8'))  # Set update interval 100ms
        sleep(1)
        ser.write(MEAS_100msec.encode('utf-8'))    # Set measurement interval 100ms
        sleep(1)
        ser.write(GPRMC_ONLY.encode('utf-8'))      # Set report GPRMC message only
        sleep(1)
        ser.flushInput()
        ser.flushOutput()
        print("GPS is Initialized\n")

gps=GPS() #GPS is set when the instance is initialized
while(1):
    while ser.inWaiting()==0:
        pass
    data=ser.readline()
    #Write the processing of the acquired data here
    print(data)

Why are the update and measurement settings separate? I think it's meaningless if it doesn't work together.

Recommended Posts

Get data from GPS module at 10Hz in Python
Get data from Quandl in Python
Get time series data from k-db.com in Python
Get Leap Motion data in Python.
Hit REST in Python to get data from New Relic
Get additional data in LDAP with python
[Note] Get data from PostgreSQL with Python
Get Google Fit API data in Python
Get Youtube data in Python using Youtube Data API
Get battery level from SwitchBot in Python
Get Precipitation Probability from XML in Python
Get metric history from MLflow in Python
Get only articles from web pages in Python
Get date in Python
Receive dictionary data from a Python program in AppleScript
Get LEAD data using Marketo's REST API in Python
Get data from database via ODBC with Python (Access)
Generate Word Cloud from case law data in python3
Get YouTube Comments in Python
Get structural data from CHEMBLID
Handle Ambient data in Python
Get last month in python
Display UTM-30LX data in Python
Get Youtube data with python
OCR from PDF in Python
Get Terminal size in Python
Explicitly get EOF in python
Get Evernote notes in Python
Get Japanese synonyms in Python
Get your heart rate from the fitbit API in Python!
Get the value while specifying the default value from dict in Python
Get macro constants from C (++) header file (.h) in Python
Get data from analytics API with Google API Client for python
Get message from first offset with kafka consumer in python
Python: Exclude tags from html data
[Python] logging in your own module
Read Protocol Buffers data in Python3
Hit treasure data from Python Pandas
Get the desktop path in Python
Handle NetCDF format data in Python
How to get a string from a command line argument in python
Get the script path in Python
Get data from MySQL on a VPS with Python 3 and SQLAlchemy
Extract text from images in Python
Hashing data in R and Python
Get, post communication memo in Python
Python unittest module execution in vs2017
Get upcoming weather from python weather api
Conditional element extraction from data frame: R is% in%, Python is .isin ()
Get the desktop path in Python
Get the host name in Python
Get data from Twitter using Tweepy
Get started with Python in Blender
Master the weakref module in Python
Extract strings from files in Python
How to get a value from a parameter store in lambda (using python)
Get options in Python from both JSON files and command line arguments
Get a datetime instance at any time of the day in Python
Get the key for the second layer migration of JSON data in python
Receive textual data from mysql with python
Get html from element with Python selenium