This part has a page of its own, with a note on using it and a circuit to try: the part page.
To a sketch it is a serial port that talks NMEA at 9600 baud. Aliases: GPS, GNSS receiver, u-blox.
There is no sky in Mokxi. The position is a property of the part, and whether the
module has a fix is a switch you throw by clicking it. What is real is everything
the board sees: the bytes on TX, bit by bit, in the sentences a real NEO-6M
sends from the factory.
Pins
| Pin | What it does |
|---|---|
VCC |
Supply, 3 to 5 V. The breakout has its own 3.3 V regulator. |
RX |
Into the module. Accepted and ignored: see below. |
TX |
Out of the module: NMEA at baud, 8N1, swinging to 3.3 V. |
GND |
Ground. |
Wire TX to a receive pin on the board. On a Mega that is RX1 (pin 19) and the
sketch reads Serial1. On an ESP32 DevKit it is RX2 (GPIO 16), with
Serial2.begin(9600, SERIAL_8N1, 16, 17);. The Uno's only hardware UART is the serial monitor's, so
on an Uno the tutorials reach for SoftwareSerial, and it works as they write
it:
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
SoftwareSerial gpsSerial(4, 3); // the module's TX into pin 4
TinyGPSPlus gps;
void setup() { Serial.begin(115200); gpsSerial.begin(9600); }
void loop() {
while (gpsSerial.available() > 0) gps.encode(gpsSerial.read());
if (gps.location.isUpdated()) {
Serial.print(gps.location.lat(), 6);
Serial.print(",");
Serial.println(gps.location.lng(), 6);
}
}
Keep the serial monitor fast, at 115200 as the TinyGPS++ examples do. At 9600 a
printed line takes about as long as 70 bytes from the module, and
SoftwareSerial's 64-byte buffer overflows while it prints: the GGA sentence,
with the satellites and the altitude, is the one that goes missing. The same
sketch runs on an ESP8266 or an ESP32 with the pins changed (the NodeMCU's D5
and D6, say).
Properties
lat and lon are where the module is, in decimal degrees (north and east are
positive). altitude is meters above sea level. satellites is how many it
reports using, 0 to 12; fewer than three is no fix. speed in km/h and course
in degrees from north make the position move along that heading once a second.
fix is whether it starts with one. start is the UTC date and time at the first
sentence. baud is 9600, as shipped.
While it runs
Click the module to lose the fix and click again to get it back. The badge on the face says which, and the green LED blinks for 100 ms each second while there is a fix, as the real one's timepulse does.
What is modeled
The default u-blox 6 output: every second, $GPRMC, $GPVTG, $GPGGA, $GPGSA,
one to three $GPGSV and $GPGLL, each with its checksum and CR LF. About 450
bytes, which at 9600 baud keeps the wire busy for nearly half of every second,
exactly as on the bench. The position goes out to five decimal places of a minute.
Without a fix the sentences are the empty ones a receiver sends indoors: status
V, fix quality 0, no time and no position.
TinyGPS++.h reads it: gps.encode(c) on every byte, then gps.location.lat(),
gps.location.lng(), gps.date, gps.time, gps.speed.kmph(),
gps.course.deg(), gps.altitude.meters(), gps.satellites.value() and
gps.hdop.hdop(), with isValid(), isUpdated() and age() on each, and
TinyGPSPlus::cardinal() for the compass point of a course.
Every value comes back as a double built from the whole numbers in the
sentence, so it prints exactly, with as many decimals as you ask for, and a
sketch can do sums on it like any other number. distanceBetween and
courseTo work too: the great-circle distance in meters and the course in
degrees, as the upstream library gives them. On the AVR boards a double is
32 bits, so a position there is good to about a meter.
The GPS logger in the gallery puts this module and a microSD card on a Mega and
writes a track you can download. GPS position puts it on an Uno with
SoftwareSerial.
What is not modeled
The radio and everything that comes from it: acquiring satellites, the half
minute a cold start really takes (here the fix is there at the first second), a
stationary fix wandering by a few meters, multipath, the backup battery. Commands
on RX (UBX or $PUBX) change nothing, so the rate cannot be changed from a
sketch. The geoid separation is always 0.0.
See it in action
The tutorial Arduino NEO-6M GPS wires the module to
an Uno with SoftwareSerial and TinyGPS++, moves it, and takes its fix away.
The GPS speedometer with a trip odometer shows speed and heading from one of these with NeoGPS, and keeps a trip odometer in EEPROM.
Related
- GPS module, NEO-6M: the part page, with the pinout and key facts.