gsm-connexion.ino

Arduino MKR GSM 1400 · File : gsm-connexion.ino · Language : Arduino · Use case : Se connecter au réseau cellulaire 2G et afficher le statut

The essential first step with the MKR GSM 1400: initialise the u-blox modem, check that the SIM is recognised, then wait for registration on a 2G network. The sketch prints the operator name and signal quality on the serial monitor at 9600 baud.

Hardware

An Arduino MKR GSM 1400 (SAMD21 microcontroller, 2G/GPRS cellular modem, external antenna, powered by a LiPo battery on the J6 connector or over USB). One active 2G data SIM card (micro format), a 2G antenna screwed onto the SMA connector, and a micro-USB cable.

Wiring

No external wiring: insert the SIM contacts-down on the edge opposite the USB, screw the antenna in, plug in USB.

How it works

gsm.begin() powers the modem and unlocks the SIM with the PIN. waitNetworkReady(30) polls registration every second up to a 30 s timeout. getOperator() and getSignalQuality() confirm the radio link.

Running it

In the Arduino IDE, install the Arduino SAMD Boards package, select the MKR GSM 1400 board, then upload. Network examples assume an active data SIM is inserted, the antenna is screwed on, and 2G coverage still exists in your area.

Variants

Disable the SIM PIN (through a phone) and pass an empty PIN_SIM for a faster boot; also try getIMSI().

gsm-connexion.ino

// Connexion au réseau avec le MKR GSM 1400 (bibliothèque MKRGSM).
#include <MKRGSM.h>

const char PIN_SIM[] = "0000"; // "0000" ou "" si code PIN désactivé
const char APN[] = "sl2g";      // APN 2G de votre opérateur

GSM gsm;
GSMClient client;

void setup() {
  Serial.begin(9600);
  while (!Serial);
  Serial.println(F("Init modem GSM..."));
  if (gsm.begin(PIN_SIM) != GSM_READY) {
    Serial.println(F("Modem indisponible, verif. SIM/antenne"));
    while (true);
  }
  Serial.println(F("Modem pret, attachement reseau..."));
  if (gsm.waitNetworkReady(30) == ON_NET) {
    Serial.print(F("Enregistre sur : "));
    Serial.println(g.getOperator());
    Serial.print(F("Signal : "));
    Serial.println(g.getSignalQuality());
  } else {
    Serial.println(F("Echec attachement, relance..."));
    gsm.restart();
  }
}

void loop() {}

← Back to the board