🛠 Position GPS via shield et Serial1
Objectives
Retrieve a GPS position and upload it via the cellular network. Note: the MKR NB 1500 does not include a documented GPS receiver — the SARA-R410M-02B module on this board has no confirmed GNSS according to the official datasheet. The standard method, used by community tracker projects, is a GPS shield (or external NMEA receiver) on the Serial1 port (SERCOM5, RX PB23 / TX PB22).
Hardware
- 1 MKR NB 1500 board + cellular antenna + data SIM
- 1 GPS NMEA shield or module, 3.3 V (e.g., MKR GPS / NEO-6M 3.3 V version) on Serial1
- A GPS antenna separate from the cellular antenna, spaced at least a few cm apart
Complete code
// Position NMEA sur Serial1 + log serie — MKR NB 1500
#include <MKRGSM.h>
GSM gsm; // pour eteindre le modem pendant les essais
void setup {
Serial.begin(9600); // console USB
Serial1.begin(9600); // shield GPS (baud typique NEO-6M : 9600)
while (!Serial);
gsm.begin;
gsm.shutdown; // radio cellulaire coupee pour ce test
}
String ligne;
void loop {
while (Serial1.available) {
char c = Serial1.read;
if (c == '\n') {
if (ligne.startsWith("$GPGGA")) { // trame position
Serial.println(ligne);
// extraire lat/lon : champs 2 a 6 de la trame GPGGA
}
ligne = "";
} else if (ligne.length < 120) {
ligne += c;
}
}
}
Expected verification
Outdoors, with a clear view of the sky, the console scrolls through NMEA frames, and then $GPGGA frames contain latitude/longitude after the first fix (30 to 60 seconds for a cold start). Once validated, replace gsm.shutdown with network attachment and publish the position via MQTT (next tutorial).
Common errors
- Looking for a non-existent "integrated" GPS: without a shield/external receiver, there is no positioning on this board (the NB-IoT module provides at best a very imprecise cellular location, not documented here).
- 5 V GPS module on 3.3 V Serial1: check the logic level; a NEO-6M powered at 5 V outputs 5 V on TX.
- First fix never obtained indoors: GPS does not penetrate concrete; test outdoors.
- GPS and cellular antennas stuck together: the cellular antenna interferes with the GPS receiver; separate them.
- Incorrect NMEA baud rate: some shields transmit at 38400; adjust
Serial1.begin.
Other tutorials for this board
Code examples for this board
attente-lte-nbiot.inoArduinochoix-bande.inoArduinopublish-mqtt-minimal.inoArduinoeconomie-energie.inoArduinogeoloc-cellules.inoArduinotest-coverage.inoArduino