🛠 Position GPS via shield et Serial1

Arduino MKR NB 1500 · intermediaire · Schéma : IMG-mkr-nb-1500-intermediaire-3-mkrnb-gps-shield.svg — MKR NB 1500 avec un shield GPS superposé communiquant en série sur les broches TX/RX (Serial1), antenne GPS et antenne cellulaire distinctes

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

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

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials