choix-bande.ino
A LPWA module finding no network is often misconfigured: this sketch reads then forces the LTE band mask (B3/B7/B8/B20 for France) and the CAT-M1/NB1 mode of the MKR NB 1500 SARA-R4. Run once, the setting persists in flash.
Hardware
An Arduino MKR NB 1500 (SAMD21 microcontroller, u-blox LTE-M/NB-IoT modem, external antenna, LiPo power on J6 or USB). MKR NB 1500, IoT SIM, multi-band antenna covering the chosen bands.
Wiring
No wiring; the program is flashed once, then the module keeps the radio configuration in flash memory.
How it works
The band mask is a bit-wise hexadecimal (b0=B1...). setBandMask and setNetworkSettings write into the modem profile; a restart applies the radio changes.
Running it
Install the Arduino SAMD Boards package and the MKRNB library, select the board, upload. Plan for an activated IoT SIM (LTE-M or NB1) and good reception: attaching to the network can take several minutes.
Variants
Adapt the mask to your operator/region (B12/B13 in rural US), or test each band separately to unmask a mediocre antenna.
choix-bande.ino
// Selection bande + mode radio du SARA-R4 (MKR NB 1500, MKRNB).
#include <MKRNB.h>
const char PIN_SIM[] = "0000";
NB nb;
// Bandes Europe Telecom France : B3/B7/B8/B20
// Modes : "3" = CAT-M1, "4" = NB1, "3,4" = les deux
const char BANDES[] = "800000000020001B"; // B3,B7,B8,B20 (masque hexa)
const char MODE[] = "3,4";
void setup() {
Serial.begin(9600);
while (!Serial);
if (nb.begin(PIN_SIM) != NB_READY) while (true);
Serial.println(F("Lecture bande courante..."));
Serial.println(nb.getBandMask());
Serial.println(F("Application du masque de bandes..."));
if (nb.setBandMask(BANDES) == RIL_OK) Serial.println(F("Bandes OK"));
else Serial.println(F("Bandes refusees"));
Serial.println(F("Mode radio..."));
if (nb.setNetworkSettings(MODE) == RIL_OK) Serial.println(F("Mode OK"));
Serial.println(F("Reinitialisation modem pour appliquer..."));
nb.restart();
Serial.println(F("Relancez apres reconnexion du port serie."));
}
void loop() {}