Arduino library · Communication

MicroNMEA: an example that runs

Yes. You can use the MicroNMEA 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, "Fix, time and position from a NEO-6M with MicroNMEA", runs on the Arduino Uno R3.

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

What MicroNMEA does

A small NMEA parser with no floating point: process() a character at a time, then the fix, latitude and longitude in millionths of a degree, time, date, speed, course, altitude, satellites and HDOP from RMC and GGA. That is what MicroNMEA, by Steve Marple, covers. The sketch below uses it on the Arduino Uno: “Fix, time and position from a NEO-6M with MicroNMEA”.

Steve Marple's compact NMEA parser for GPS and GNSS receivers, all integer arithmetic, into a buffer the sketch provides.

The calls follow release 2.0.6 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 nameMicroNMEA
AuthorSteve Marple
Include#include <MicroNMEA.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 <MicroNMEA.h> and the sketch compiles, with no download, no zip and no Library Manager.

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

What to know in the simulator: The other sentences reach the unknown sentence handler. sendSentence() adds the checksum and writes the line, which the NEO-6M ignores, as a real one does with commands it does not know.

The calls you will use

In the order a sketch meets them.

MicroNMEA nmea(nmeaBuffer, sizeof(nmeaBuffer))

Makes nmea, the MicroNMEA object the calls below are made on.

nmea.setUnknownSentenceHandler(countUnknownSentence)

Sets the unknown sentence handler.

nmea.getMessageID()

Returns the message id as text.

nmea.isValid()

Returns true or false for "is valid".

nmea.getNavSystem()

Returns the nav system as a whole number.

nmea.getNumSatellites()

Returns the num satellites as a whole number.

nmea.getYear()

Returns the year as a whole number.

nmea.getMonth()

Returns the month as a whole number.

nmea.getDay()

Returns the day as a whole number.

Example: Fix, time and position from a NEO-6M with MicroNMEA

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

sketch.ino · Arduino Uno R3
#include <SoftwareSerial.h>
#include <MicroNMEA.h>

// The demo reads Serial1 and prints on the PPS pulse; an Uno reads the module
// on a software serial port and prints once each second's GGA has come in.
SoftwareSerial gps(4, 3);  // the GPS's TX, RX

char nmeaBuffer[100];
MicroNMEA nmea(nmeaBuffer, sizeof(nmeaBuffer));
unsigned int unknown = 0;

void countUnknownSentence(MicroNMEA&) {
  unknown++;
}

void setup(void) {
  Serial.begin(115200);
  gps.begin(9600);
  nmea.setUnknownSentenceHandler(countUnknownSentence);
  Serial.println("Waiting for the GPS ...");
}

void loop(void) {
  while (gps.available()) {
    char c = gps.read();
    if (nmea.process(c) && strcmp(nmea.getMessageID(), "GGA") == 0) {
      Serial.print("Valid fix: ");
      Serial.println(nmea.isValid() ? "yes" : "no");

      Serial.print("Nav. system: ");
      if (nmea.getNavSystem())
        Serial.println(nmea.getNavSystem());
      else
        Serial.println("none");

      Serial.print("Num. satellites: ");
      Serial.println(nmea.getNumSatellites());

      Serial.print("Date/time: ");
      Serial.print(nmea.getYear());
      Serial.print('-');
      Serial.print(int(nmea.getMonth()));
      Serial.print('-');
      Serial.print(int(nmea.getDay()));
      Serial.print('T');
      Serial.print(int(nmea.getHour()));
      Serial.print(':');
      Serial.print(int(nmea.getMinute()));
      Serial.print(':');
      Serial.println(int(nmea.getSecond()));

      Serial.print("Latitude (millionths of a degree): ");
      Serial.println(nmea.getLatitude());
      Serial.print("Longitude (millionths of a degree): ");
      Serial.println(nmea.getLongitude());

      long alt;
      Serial.print("Altitude (mm): ");
      if (nmea.getAltitude(alt))
        Serial.println(alt);
      else
        Serial.println("not available");

      Serial.print("Other sentences: ");
      Serial.println(unknown);
      Serial.println("-----------------------");
      nmea.clear();
    }
  }
}

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

Try MicroNMEA without installing anything

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