Using NB-IoT or Cat-M1 with the Portenta Max Carrier

Learn how to connect the Portenta Max Carrier to the internet with NB-IoT or Cat-M1 technology


The Arduino® Portenta Max Carrier adds a lot of functionality to the Portenta H7. With the Portenta Max Carrier it is possible to use NB-IoT and Cat-M1 technology. In this tutorial we will show to connect to GSM with the Portenta Max Carrier and the Portenta H7.

Note: This tutorial was created in Sweden, and as a result, the available networks are only Swedish network operators. The results will vary depending on what location you are in.


The goals of this project are:

  • Learn how to connect the board and the carrier.
  • Connect to the GSM network with Cat-M1 or NB-IoT.
  • Print HTML content in the Serial Monitor.

Hardware & Software Needed



For this tutorial we need to plug the Portenta H7 into the Max Carrier, like shown in the image below. By attaching the Portenta H7 board to the HD connectors on top of the carrier, press firmly to let it snap in. Once attached, plug the Portenta H7 into your computer using a USB-C cable.

Connecting the Portenta H7 and Max Carrier

And we also need to insert a SIM card and connect an antenna to the Max Carrier, like shown in the image below. Put the SIM card into the SIM card slot at the top of the carrier, the same side where the Portenta H7 is located. Next to the SIM card slot there is an antenna SMA connector where you will need to screw on your antenna.

SIM card slot and antenna connector

After everything else is connected, connect a power cable to the barrel jack. The one right next to the SMA antenna connector.

Arduino IDE

In the Arduino IDE, make sure you have the latest Portenta mbed os Core installed. Found in Tools > Board: > boards manager....

We will also need two libraries to be installed, MKRNB and arduino_bq24195. You can find these in the Library manager in the Arduino IDE. We will be using example sketches from the MKRNB library. The arduino_bq24195 library allows us to control and configuration the BQ24195 PMIC used on the Portenta Max Carrier.

NB-IoT or Cat-M1

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. While Cat-M1 supports downlink and uplink speeds up to 1 Mbps with a latency of 50 to 100 ms and can be used for realtime-communication. Cat-M1 is ideal if you are interested in tracking things such as logistics and transportation. Make sure the technology that you choose is supported by your service provider.

Switching Between NB-IoT and Cat-M1

If you prefer to use one communication technology over the other, then this can be changed with the simple use of one sketch. Open the ChoseRadioAccessTechnology sketch located in the MKRNB examples. When this sketch is uploaded, open the serial monitor. You will now get options for what technology you prefer to use in the serial monitor. Follow the steps and wait for the sketch to say that it is finished. The board will now use the preferred technology and we can move on to upload other sketches.

Serial monitor for sketch
Serial monitor for sketch

Programming the Board

Now open the NBWebClient example, this is located inside the MKRNB. The full sketch will also be included later in this tutorial. This sketch will connect the our setup to a website and print its content in the serial monitor.

This sketch uses a secret.h file to store sensitive information, like the PIN code for the SIM card. First we need to go to the arduino_secrets.h tab and enter our PIN code into the Secret_pinnumber variable.

The char server[] variable will decide what website the setup will connect to and print in the serial monitor. Feel free to try different sites and see the difference in the result. In this tutorial we will use the default

The sketch will also set the port it uses for connecting with int port = 80;. This is the default connection port. If the connection is not being established or if you know the specific port you want to connect to, then change this variable to a more appropriate value.

Result of Sketch

When the sketch is uploaded, open the serial monitor to see the result. You will get error messages in the serial monitor if there is some issue along the way. When it works you should see something similar to what is shown below.

Result in the serial monitor
Result in the serial monitor

Full Sketch

1// libraries
2#include <MKRNB.h>
4#include "arduino_secrets.h"
5// Please enter your sensitive data in the Secret tab or arduino_secrets.h
6// PIN Number
9// initialize the library instance
10NBClient client;
11GPRS gprs;
12NB nbAccess;
14// URL, path and port (for example:
15char server[] = "";
16char path[] = "/";
17int port = 80; // port 80 is the default for HTTP
19void setup() {
20 // initialize serial communications and wait for port to open:
21 Serial.begin(9600);
22 while (!Serial) {
23 ; // wait for serial port to connect. Needed for native USB port only
24 }
26 Serial.println("Starting Arduino web client.");
27 // connection state
28 boolean connected = false;
30 // After starting the modem with NB.begin()
31 // attach to the GPRS network with the APN, login and password
32 while (!connected) {
33 if ((nbAccess.begin(PINNUMBER) == NB_READY) &&
34 (gprs.attachGPRS() == GPRS_READY)) {
35 connected = true;
36 } else {
37 Serial.println("Not connected");
38 delay(1000);
39 }
40 }
42 Serial.println("connecting...");
44 // if you get a connection, report back via serial:
45 if (client.connect(server, port)) {
46 Serial.println("connected");
47 // Make a HTTP request:
48 client.print("GET ");
49 client.print(path);
50 client.println(" HTTP/1.1");
51 client.print("Host: ");
52 client.println(server);
53 client.println("Connection: close");
54 client.println();
55 } else {
56 // if you didn't get a connection to the server:
57 Serial.println("connection failed");
58 }
61void loop() {
62 // if there are incoming bytes available
63 // from the server, read them and print them:
64 if (client.available()) {
65 Serial.print((char);
66 }
68 // if the server's disconnected, stop the client:
69 if (!client.available() && !client.connected()) {
70 Serial.println();
71 Serial.println("disconnecting.");
72 client.stop();
74 // do nothing forevermore:
75 for (;;)
76 ;
77 }


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

  • We have entered the wrong pin number.
  • We are out of coverage (no signal). You can run the example sketch Scan available networks to see if there is coverage.
  • SIM card may not be activated.

Next Step


In this tutorial we went through how to connect the Portenta H7 and Portenta Max Carrier, with peripherals to be able to use the carriers GSM feature. We then learned how to set a preference between NB-IoT or Cat-M1 technology. And at the end we tested so everything works by running an example sketch on our setup.