Arduino library · Communication

NeoGPS: an example that runs

Yes. You can use the NeoGPS library online in Mokxi with nothing to install, and the sketch runs in your browser against the simulated part (GPS module, NEO-6M). The example below, "NMEAsimple: location and altitude from a NEO-6M with NeoGPS", runs on the Arduino Uno R3.

Built in on Mokxi: #include <NMEAGPS.h> and it builds, with nothing to install. Free, and no account needed.

What NeoGPS does

NMEAGPS in its shipped configuration: gps.available(port) and gps.read() hand over a whole gps_fix each second with valid flags, latitudeL() in 1e-7 degrees, altitude, speed, heading, satellites and dateTime, Location_t distances and bearings, and GPSport.h. That is what NeoGPS, by SlashDevin, covers. The sketch below uses it on the Arduino Uno: “NMEAsimple: location and altitude from a NEO-6M with NeoGPS”.

SlashDevin's NeoGPS, the NMEA parser that hands the sketch a whole fix (gps_fix) once per second, in its default configuration.

The macros say so (NMEAGPS_PARSE_GGA, NMEAGPS_PARSE_RMC, GPS_FIX_LOCATION and the rest), so a sketch's own #ifndef ... #error checks pass. HDOP, the satellite list, DMS locations, interrupt processing and the u-blox and Garmin classes are not here.

The calls follow release 4.2.9 of the library, so a sketch written here builds on a real board too. The example is the one Mokxi's own tests build and run, so what is printed here is what runs.

Library Manager nameNeoGPS
AuthorSlashDevin
Include#include <NMEAGPS.h>
#include <GPSport.h>
BoardsArduino Uno, Arduino Nano, Arduino Mega 2560, Arduino Leonardo, SparkFun Pro Micro, Arduino Micro, Arduino Pro Mini 3.3 V, ESP8266 NodeMCU, ESP32 DevKit, ESP32-DevKitC V4, LOLIN32 Lite, Wemos D1 R32, Cheap Yellow Display, TTGO T-Display, ESP32-S3-DevKitC-1, Seeed XIAO ESP32-S3, Arduino Nano ESP32
In the simulatorSimulated: it runs against the part the way it does on the bench.
Parts it drivesGPS module, NEO-6M

Install it

It builds on Arduino Uno, Arduino Nano, Arduino Mega 2560, Arduino Leonardo, SparkFun Pro Micro, Arduino Micro, Arduino Pro Mini 3.3 V, ESP8266 NodeMCU, ESP32 DevKit, ESP32-DevKitC V4, LOLIN32 Lite, Wemos D1 R32, Cheap Yellow Display, TTGO T-Display, ESP32-S3-DevKitC-1, Seeed XIAO ESP32-S3, Arduino Nano ESP32.

In Mokxi it is built in: #include <NMEAGPS.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "NeoGPS" by SlashDevin from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add NeoGPS to lib_deps in PlatformIO. Mokxi follows the calls of release 4.2.9, so a sketch written here builds there too.

What to know in the simulator: Upstream is configured by editing its _cfg.h files; this is the shipped configuration (GGA and RMC parsed, RMC ends the second, explicit merging), which cannot be changed. HDOP, the satellite list, DMS, interrupt processing, the ublox classes and Streamers.h are not here.

The calls you will use

In the order a sketch meets them.

NMEAGPS gps

Makes gps, the NMEAGPS object the calls below are made on.

gps_fix fix

Makes fix, the gps_fix object the calls below are made on.

gps.read()

Returns the value as a gps_fix.

fix.latitude()

Returns the latitude as a decimal number.

fix.longitude()

Returns the longitude as a decimal number.

fix.altitude()

Returns the altitude as a decimal number.

Example: NMEAsimple: location and altitude from a NEO-6M with NeoGPS

On the Arduino Uno R3. It runs in the browser exactly as printed.

sketch.ino · Arduino Uno R3
#include <SoftwareSerial.h>  // GPSport.h then puts the GPS on pins 4 (RX) and 3 (TX)
#include <NMEAGPS.h>
#include <GPSport.h>

NMEAGPS  gps; // This parses the GPS characters
gps_fix  fix; // This holds on to the latest values

void setup()
{
  DEBUG_PORT.begin(9600);
  while (!Serial)
    ;
  DEBUG_PORT.print( F("NMEAsimple.INO: started\n") );

  gpsPort.begin(9600);
}

void loop()
{
  while (gps.available( gpsPort )) {
    fix = gps.read();

    DEBUG_PORT.print( F("Location: ") );
    if (fix.valid.location) {
      DEBUG_PORT.print( fix.latitude(), 6 );
      DEBUG_PORT.print( ',' );
      DEBUG_PORT.print( fix.longitude(), 6 );
    }

    DEBUG_PORT.print( F(", Altitude: ") );
    if (fix.valid.altitude)
      DEBUG_PORT.print( fix.altitude() );

    DEBUG_PORT.print( F(", Satellites: ") );
    if (fix.valid.satellites)
      DEBUG_PORT.print( fix.satellites );

    DEBUG_PORT.print( F(", Time: ") );
    DEBUG_PORT << fix.dateTime;

    DEBUG_PORT.println();
  }
}

Wiring

  • GPS module, NEO-6M TX to Arduino Uno R3 4
  • GPS module, NEO-6M RX to Arduino Uno R3 3
  • Arduino Uno R3 5V to GPS module, NEO-6M VCC
  • Arduino Uno R3 GND to GPS module, NEO-6M GND

Open it in the editor, wired and ready to run

Projects that use NeoGPS

Built-in projects that include it. Each page has the full sketch and opens in the editor, already wired.

Try NeoGPS without installing anything

Open the example, change the sketch, and keep your version in a free account.