Radio Access Technology Configuration for MKR NB 1500

Learn how to choose between different configurations (NB-IoT and CAT-M1) and save the changes on the modem.

Introduction

In this tutorial, we will learn how to set the preferred Narrowband Radio Access Technology (RAT) for the MKR NB 1500 board.

Before we can start using our MKR NB 1500 board with a SIM card, we need to set the preferred RAT. You can choose among LTE CAT-M1, NB-IoT or a combination of both. The chosen configuration will be saved in the modem's internal memory and will be preserved through MKR NB 1500 sketch uploads.

If you are unsure about what setting is best for your location, please refer to this mobile IoT deployment map. Here we can for example see that most parts of Western Europe, North America and Australia can use both LTE-M and NB-IoT, which means we have multiple options to choose from. Most parts of Asia however, can only use the NB-IoT access technology, while Africa in general does not have much coverage.

Goals

The goals of this project are:

  • Set preferred narrowband technology.
  • Get the NB 1500 ready for use.

Hardware & Software Needed

Circuit

The circuit for this tutorial is very simple. All we need is an antenna connected to the MKR NB 1500 board.

Simple circuit of the board with antenna.
Simple circuit of the board with antenna.

A Quick Comparison of Radio Technologies

The MKR NB 1500 board has the capability to connect to either NB-IoT or LTE-M, each with their own promising features. Let's take a quick look at them!

NB-IoT

NB-IoT is a radio technology deployed over mobile networks which is especially suited for indoor coverage, low cost, long battery life, and large number of devices.

LTE-M

LTE-M supports downlink and uplink speeds up to 1 Mbps with a latency of 50 to 100 ms and can be used for realtime-communication. LTE-M is ideal if you are interested in tracking things such as logistics and transportation.

Every time we decide to change the RAT, we can run this sketch again.

Creating the Program

We will now get to the programming part of this tutorial. It focuses on two main parts: choosing what RAT the board will use, and saving it to the modem's internal memory.

1. First, let's make sure we have the drivers installed. If we are using the Web Editor, we do not need to install anything. If we are using an offline editor, we need to install it manually. This can be done by navigating to Tools > Board > Board Manager.... Here we need to look for the Arduino SAMD boards (32-bits Arm® Cortex®-M0+) and install it.

2. Now, we need to install the libraries needed. If we are using the Web Editor, there is no need to install anything. If we are using an offline editor, simply go to Tools > Manage libraries.., and search for MKRNB and install it.

3. With the drivers and library installed, we can now move on to create the sketch. This sketch is available as an example in the MKRNB library, and can be accessed directly through the editor by navigating to File > Examples > MKRNB > Tools > ChangeRadioAccessTechnology.

The full code is also available further down this tutorial. But we will now also go through it step by step to understand the sketch a bit better.

First we need to include the MKRNB library to access its functionalities. We then initialize the boards modem, making it possible to write to the modems internal memory. Lastly, in setup we then make the code print a text based interface to the serial monitor, enabling us to see our options and select the option that suits us best.

1#include <MKRNB.h>
2
3void setup() {
4 Serial.begin(115200);
5 while (!Serial);
6 MODEM.begin();
7 while (!MODEM.noop());
8 Serial.println();
9 Serial.println("Please choose your Radio Access Technology:");
10 Serial.println();
11 Serial.println(" 0 - LTE CAT M1 only");
12 Serial.println(" 1 - NB IoT only");
13 Serial.println(" 2 - LTE CAT M1 preferred, NB IoT as failover (default)");
14 Serial.println(" 3 - NB IoT preferred, LTE CAT M1 as failover");
15 Serial.println();
16}

In the loop() function, we read the answer given in the serial monitor, giving a variable the appropriate value so that the right setting will be applied to the internal memory. Calling on our custom functions and sending the appropriate variables at the end.

1void loop() {
2 String uratChoice;
3 Serial.print("> ");
4 Serial.setTimeout(-1);
5 while (Serial.available() == 0);
6 String uratInput = Serial.readStringUntil('\n'); //Reads the user input that is written before enter is hit
7 uratInput.trim();
8 int urat = uratInput.toInt(); //Converts the input into an int, making it possible to pass into the switch function
9 Serial.println(urat);
10 switch (urat) {
11
12 case 0:
13 uratChoice = "7";
14 break;
15
16 case 1:
17 uratChoice = "8";
18 break;
19
20 case 2:
21 uratChoice = "7,8";
22 break;
23
24 case 3:
25 uratChoice = "8,7";
26 break;
27
28 default:
29 //If an invalid value is entered into the serial monitor this case will catch it
30 Serial.println("Invalid input. Please, retry.");
31 return;
32 }
33 setRAT(uratChoice);
34 apply();
35 Serial.println();
36 Serial.println("Radio Access Technology selected.");
37 Serial.println("Now you can upload your 4G application sketch.");
38 while (true);
39}

setRAT(String choice) writes the preferred RAT choice to the modem. We send our choice to this function, using the variable called

choice
. Using our choice from the serial monitor the function sets the preferred RAT for this board.

1bool setRAT(String choice)
2{
3 String response;
4 Serial.print("Disconnecting from network: ");
5 MODEM.sendf("AT+COPS=2");
6 MODEM.waitForResponse(2000);
7 Serial.println("done.");
8 Serial.print("Setting Radio Access Technology: ");
9 MODEM.sendf("AT+URAT=%s", choice.c_str());
10 MODEM.waitForResponse(2000, &response);
11 Serial.println("done.");
12 return true;
13}

apply() saves the RAT choice to the modems internal memory. The last function wrote the desired option to the board, this function will save that choice to the modems internal memory. Ensuring that the correct RAT option stays on the boards internal memory, even when uploading new sketches to the board.

1bool apply()
2{
3 Serial.print("Applying changes and saving configuration: ");
4 MODEM.send("AT+CFUN=15");
5 MODEM.waitForResponse(5000);
6 delay(5000);
7 do {
8 delay(1000);
9 MODEM.noop();
10 } while (MODEM.waitForResponse(1000) != 1);
11 Serial.println("done.");
12 return true;
13}

Complete Code

1#include <MKRNB.h>
2
3void setup() {
4 Serial.begin(115200);
5 while (!Serial);
6 MODEM.begin();
7 while (!MODEM.noop());
8 Serial.println();
9 Serial.println("Please choose your Radio Access Technology:");
10 Serial.println();
11 Serial.println(" 0 - CAT M1 only");
12 Serial.println(" 1 - NB IoT only");
13 Serial.println(" 2 - CAT M1 preferred, NB IoT as failover (default)");
14 Serial.println(" 3 - NB IoT preferred, CAT M1 as failover");
15 Serial.println();
16}
17
18void loop() {
19 String uratChoice;
20 Serial.print("> ");
21 Serial.setTimeout(-1);
22 while (Serial.available() == 0);
23 String uratInput = Serial.readStringUntil('\n');
24 uratInput.trim();
25 int urat = uratInput.toInt();
26 Serial.println(urat);
27 switch (urat) {
28
29 case 0:
30 uratChoice = "7";
31 break;
32
33 case 1:
34 uratChoice = "8";
35 break;
36
37 case 2:
38 uratChoice = "7,8";
39 break;
40
41 case 3:
42 uratChoice = "8,7";
43 break;
44
45 default:
46 Serial.println("Invalid input. Please, retry.");
47 return;
48 }
49 setRAT(uratChoice);
50 apply();
51 Serial.println();
52 Serial.println("Radio Access Technology selected.");
53 Serial.println("Now you can upload your 4G application sketch.");
54 while (true);
55}
56
57bool setRAT(String choice)
58{
59 String response;
60 Serial.print("Disconnecting from network: ");
61 MODEM.sendf("AT+COPS=2");
62 MODEM.waitForResponse(2000);
63 Serial.println("done.");
64 Serial.print("Setting Radio Access Technology: ");
65 MODEM.sendf("AT+URAT=%s", choice.c_str());
66 MODEM.waitForResponse(2000, &response);
67 Serial.println("done.");
68 return true;
69}
70
71bool apply()
72{
73 Serial.print("Applying changes and saving configuration: ");
74 MODEM.send("AT+CFUN=15");
75 MODEM.waitForResponse(5000);
76 delay(5000);
77 do {
78 delay(1000);
79 MODEM.noop();
80 } while (MODEM.waitForResponse(1000) != 1);
81 Serial.println("done.");
82 return true;
83}

Testing It Out

Choosing the RAT through the Serial Monitor.
Choosing the RAT through the Serial Monitor.

After uploading the code, open the Serial Monitor, and make sure that it is open with the 115200 baud option selected. If this is correctly set up, you should see the options being printed in the Serial Monitor.

Now it is as simple as writing the number corresponding with your desired option. Writing the number and entering it into the serial monitor, will apply the setting to the board. It automatically saves it in the internal memory so that you don't have to run this code more than once, or include it in sketches that you will later upload.

Troubleshoot

If the code is not working, there are some common issues we can troubleshoot:

  • We have not updated the latest firmware for the board.
  • We have not installed the Board Package required for the board.
  • We have not selected the right port to upload: depending on what computer we use, sometimes the board is duplicated. By simply restarting the editor, this issue can be solved.

Conclusion

In this tutorial we learned how to set the Radio Access Technology (RAT) for the MKR NB 1500 board, enabling it for further use. This is a necessary step to take before sending and receiving data with a SIM card over a cellular network. Using the code in this tutorial you can easily configure your MKR NB 1500 board to use the RAT that works for your location.

Suggest changes

The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.

License

The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.