Code Monkey home page Code Monkey logo

particle-gps's Introduction

Particle-GPS

GPS library for the Particle Electron and Photon. Current version is v1.0.4.

About

Instead of porting libraries written for other platforms, this library was written from scratch using the Particle firmware. This library allows you to easily add additional sentences or support to any serial based GPS.

NMEA Output Sentences

This library will read the following NMEA sentences from the device into a buffer, but only supports parsing for the ones highlighted:

  • PGTOP (Status of antenna)
  • GGA (Time, position and fix type data)
  • GSA (GPS receiver operating mode, active satellites used in the position solution and DOP values.)
  • GSV (The number of GPS satellites in view satellite ID numbers, elevation, azimuth, and SNR values.)
  • RMC (Time, date, position, course and speed data. Recommended Minimum Navigation Information.)
  • VTG (Course and speed information relative to the ground.)

More parsing will be added in later releases. If you wish to parse additional sentences, or you need to parse custom data, take a look at Sentence.h and Sentence.cpp to see how to implement an additional parser.

Using the Library

Create the Gps Instance

Define a Gps object in your code and assign the appropriate serial port. In the example below, the serial pins on the TX and RX pins is used (Serial1).

Gps _gps = Gps(&Serial1);

Create a Timer

In order to read the serial port fast enough, a Software Timer is used. The software timer is setup to fire every 1 ms and capture data coming in on the serial pins. The line of code below creates a software timer.

Timer _timer = Timer(1, onSerialData);

In the callback function, simply call the onSerialData() method on the Gps object.

void onSerialData()
{
  _gps.onSerialData();
}

Initialize the Objects

In the setup() method, call the begin method on the Gps object.

_gps.begin(9600);

Also call the start() method of the timer.

_timer.start();

Get the Data

In the loop method, create an Nmea object for the specific data you want to read from the GPS. There are currently three NMEA sentences defined.

  1. Antenna Status ($PGTOP) => Pgtop
  2. Global Positioning System Fixed Data ($GPGGA) => Gga
  3. Recommended Minimum Navigation Information ($GPRMC) => Rmc4.

Reading Antenna Status

First create the object passing the Gps instance in the constructor.

Pgtop pgtop = Pgtop(_gps);

Next, parse the data and read the values if successful.

if (pgtop.parse())
{    
    Serial.println("1) Antenna Status ($PGTOP)");
    Serial.println("======================================================");
    Serial.print("Command ID: "); Serial.println(pgtop.commandId);
    Serial.print("Antenna Status: "); Serial.println(pgtop.reference);
    Serial.println("");
}

Global Positioning System Fixed Data

First create the object passing the Gps instance in the constructor.

Gga gga = Gga(_gps);

Next, parse the data and read the values if successful.

if (gga.parse())
{
    Serial.println("2) Global Positioning System Fixed Data ($GPGGA)");
    Serial.println("======================================================");
    Serial.print("UTC Time: "); Serial.println(gga.utcTime);
    Serial.print("Latitude: "); Serial.println(gga.latitude);
    Serial.print("North/SouthIndicator: "); Serial.println(gga.northSouthIndicator);
    Serial.print("Longitude: "); Serial.println(gga.longitude);
    Serial.print("East/WestIndicator: "); Serial.println(gga.eastWestIndicator);
    Serial.print("Position Fix Indicator: "); Serial.println(gga.positionFixIndicator);
    Serial.print("Satellites Used: "); Serial.println(gga.satellitesUsed);
    Serial.print("Horizontal Dilution of Precision: "); Serial.println(gga.hdop);
    Serial.print("Altitude: "); Serial.print(gga.altitude); Serial.print(" "); Serial.println(gga.altitudeUnit);
    Serial.print("Geoidal Separation: "); Serial.print(gga.geoidalSeparation); Serial.print(" "); Serial.println(gga.geoidalSeparationUnit);
    Serial.print("Age of Diff. Corr.: "); Serial.println(gga.ageOfDiffCorr);
    Serial.println("");
}

Recommended Minimum Navigation Information

First create the object passing the Gps instance in the constructor.

Rmc rmc = Rmc(_gps);

Next, parse the data and read the values if successful.

if (rmc.parse())
{
    Serial.println("3) Recommended Minimum Navigation Information ($GPRMC)");
    Serial.println("======================================================");
    Serial.print("UTC Time: "); Serial.println(rmc.utcTime);
    Serial.print("Latitude: "); Serial.println(rmc.latitude);
    Serial.print("North/SouthIndicator: "); Serial.println(rmc.northSouthIndicator);
    Serial.print("Longitude: "); Serial.println(rmc.longitude);
    Serial.print("East/WestIndicator: "); Serial.println(rmc.eastWestIndicator);
    Serial.print("Speed Over Ground: "); Serial.println(rmc.speedOverGround);
    Serial.print("Course Over Ground: "); Serial.println(rmc.courseOverGround);
    Serial.print("Date: "); Serial.println(rmc.date);
    Serial.print("Magnetic Variation: "); Serial.print(rmc.magneticVariation); Serial.print(" "); Serial.println(rmc.magneticVariationDirection);
    Serial.print("Mode: "); Serial.println(rmc.mode);
    Serial.println("");
}

Serial Port Debugging

Note the sample lines of code above use the serial pins connected through the USB port to send data back to the computer. Make sure the following line of code is included in your setup().

Serial.begin();

particle-gps's People

Contributors

porrey avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

particle-gps's Issues

Build

I'm not able to get this to build in the web build interface... keeps saying it can't find the header file!

Thanks,

Compiling error

I keep getting the following error during the compilation setp in the web ide : fatal error: Particle-GPS.h: No such file or directory compilation terminated. I have added the library to my project using the web ide, but the problem remains.

VS Code Particle Workbench - error: 'onSerialData' was not declared in this scope Timer _timer = Timer(1, onSerialData);

Hello,

I am able to compile the example code on the Web IDE but I get the following error when compiling in VS Code using Particle Workbench:

error: 'onSerialData' was not declared in this scope Timer _timer = Timer(1, onSerialData);

I am trying to compile this code:

/

// Copyright © 2016-2017 Daniel Porrey. All Rights Reserved.
//
// This file is part of the Particle-GPS library.
// 
// Particle-GPS library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// Particle-GPS library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with Particle-GPS library. If not, 
// see http://www.gnu.org/licenses/.
//
#include "Particle-GPS.h"

// ***
// *** Create a Gps instance. The RX an TX pins are connected to
// *** the TX and RX pins on the electron (Serial1).
// ***
Gps _gps = Gps(&Serial1);

// ***
// *** Create a timer that fires every 1 ms to capture
// *** incoming serial port data from the GPS.
// ***
Timer _timer = Timer(1, onSerialData);

void setup()
{
  delay(2000);

  // ***
  // *** Initialize the USB Serial for debugging.
  // ***
  Serial.begin();
  Serial.println("Initializing...");

  // ***
  // *** Initialize the GPS.
  // ***
  _gps.begin(9600);

  // ***
  // *** Start the timer.
  // ***
  _timer.start();
}

void onSerialData()
{
  _gps.onSerialData();
}

void loop()
{
  // ***
  // *** Get the Antenna Status ($PGTOP).
  // ***
  Pgtop pgtop = Pgtop(_gps);
  if (pgtop.parse())
  {
    Serial.println("1) Antenna Status ($PGTOP)");
    Serial.println("======================================================");
    Serial.print("Command ID: "); Serial.println(pgtop.commandId);
    Serial.print("Antenna Status: "); Serial.println(pgtop.reference);
    Serial.println("");
  }

  // ***
  // *** Get the Global Positioning System Fixed Data ($GPGGA).
  // ***
  Gga gga = Gga(_gps);
  if (gga.parse())
  {
    Serial.println("2) Global Positioning System Fixed Data ($GPGGA)");
    Serial.println("======================================================");
    Serial.print("UTC Time: "); Serial.println(gga.utcTime);
    Serial.print("Latitude: "); Serial.println(gga.latitude);
    Serial.print("North/SouthIndicator: "); Serial.println(gga.northSouthIndicator);
    Serial.print("Longitude: "); Serial.println(gga.longitude);
    Serial.print("East/WestIndicator: "); Serial.println(gga.eastWestIndicator);
    Serial.print("Position Fix Indicator: "); Serial.println(gga.positionFixIndicator);
    Serial.print("Satellites Used: "); Serial.println(gga.satellitesUsed);
    Serial.print("Horizontal Dilution of Precision: "); Serial.println(gga.hdop);
    Serial.print("Altitude: "); Serial.print(gga.altitude); Serial.print(" "); Serial.println(gga.altitudeUnit);
    Serial.print("Geoidal Separation: "); Serial.print(gga.geoidalSeparation); Serial.print(" "); Serial.println(gga.geoidalSeparationUnit);
    Serial.print("Age of Diff. Corr.: "); Serial.println(gga.ageOfDiffCorr);
    Serial.println("");
  }

  // ***
  // *** Get the Recommended Minimum Navigation Information ($GPRMC).
  // ***
  Rmc rmc = Rmc(_gps);
  if (rmc.parse())
  {
    Serial.println("3) Recommended Minimum Navigation Information ($GPRMC)");
    Serial.println("======================================================");
    Serial.print("UTC Time: "); Serial.println(rmc.utcTime);
    Serial.print("Latitude: "); Serial.println(rmc.latitude);
    Serial.print("North/SouthIndicator: "); Serial.println(rmc.northSouthIndicator);
    Serial.print("Longitude: "); Serial.println(rmc.longitude);
    Serial.print("East/WestIndicator: "); Serial.println(rmc.eastWestIndicator);
    Serial.print("Speed Over Ground: "); Serial.println(rmc.speedOverGround);
    Serial.print("Course Over Ground: "); Serial.println(rmc.courseOverGround);
    Serial.print("Date: "); Serial.println(rmc.date);
    Serial.print("Magnetic Variation: "); Serial.print(rmc.magneticVariation); Serial.print(" "); Serial.println(rmc.magneticVariationDirection);
    Serial.print("Mode: "); Serial.println(rmc.mode);
    Serial.println("");
  }

  delay(1000);
}

The function inside the timer can be peeked so the library is linked properly.

Thanks,
IceStuff

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.