🛠 Diagnostic AT du module et version de firmware
Objectives
Troubleshoot the cellular part at a low level: send AT commands to the u-blox SARA-U201 module to read signal strength, the registered operator, the module's firmware version, and check the SIM status. When MKRGSM fails in a loop without a clear message, the AT commands tell you everything: missing SIM, blocked PIN, network not found, rejected APN.
Hardware
- Arduino MKR GSM 1400 board + antenna + LiPo + SIM without PIN
- Arduino SAMD core + MKRGSM library (for
sendTestRequest, which serializes AT commands without directly controlling the UART dedicated to the modem) - Note: the modem is on a dedicated UART (
SerialGSM/Serial2, SERCOM4 with RTS/CTS flow control, pins 26-29 of the variant); the simplest approach is to use the library rather than bypassing this port.
Complete Code
#include <MKRGSM.h>
#include "arduino_secrets.h"
const char PINNUMBER[] = SECRET_PINNUMBER;
GSM gsmAccess;
void at(const char* cmd) {
Serial.print(">> "); Serial.println(cmd);
char rep[128] = {0};
// sendTestRequest envoie la chaine brute au module et recupere la reponse.
gsmAccess.sendTestRequest(cmd, rep, sizeof(rep));
Serial.print("<< "); Serial.println(rep);
}
void setup {
Serial.begin(9600);
while (!Serial) {}
at("AT"); // vie du module : doit repondre OK
at("AT+CGMR"); // version du firmware du module
at("AT+CPIN?"); // etat SIM : READY, SIM PIN, ou SIM NOT INSERTED
at("AT+CSQ"); // signal : 0..31,99 ; 99 = aucun
at("AT+COPS?"); // operateur enregistre et mode (0 = pas enregistre)
at("AT+CGREG?"); // etat d'enregistrement GPRS
at("AT+CGDCONT?"); // APN actif
// Puis tentative normale de demarrage pour croiser les indices
int r = gsmAccess.begin(PINNUMBER);
Serial.print("gsmAccess.begin = "); Serial.println(r);
}
void loop {}
Expected Verification
AT responds OK; AT+CPIN? returns READY (otherwise: SIM poorly inserted, or PIN needs unlocking with AT+CPIN="1234"); AT+CSQ gives a reasonable value between 0-31 (99 = no antenna/no network); AT+COPS? displays the operator; AT+CGMR displays the firmware version of the SARA-U201, to be noted in your maintenance log. Cross-reference with the return code of begin: 1 = SIM not initialized, 2 = network not found, 3 = GPRS error (see MKRGSM).
Common Errors
- Sending AT commands in parallel with MKRGSM: the module is controlled by the library, raw commands outside its context corrupt the state; do everything via
sendTestRequestor restart everything. - >
- Confusing the codes:
AT+CSQalso returns the bit error rate; only the first number counts for signal strength. - PIN permanently blocked (PUK) due to repeated incorrect
AT+CPINattempts: unlock with the PUK from a phone, not from the board. - Truncated multi-line responses: ensure a sufficiently large response buffer and look for "OK"/"ERROR" at the end of the response.
- 2G being phased out: a desperately empty
AT+COPS?may simply mean that the operator has shut down the band used by the board.
Other tutorials for this board
Code examples for this board
gsm-connexion.inoArduinoenvoi-sms.inoArduinohttp-get.inoArduinohttp-post-capteur.inoArduinoheure-gsm.inoArduinoappels.inoArduino