|
| 1 | +--- |
| 2 | +title: 'Using NB-IoT or Cat-M1 with the Portenta Max Carrier' |
| 3 | +difficulty: easy |
| 4 | +description: "Learn how to connect the Portenta Max Carrier to the internet with NB-IoT or Cat-M1 technology" |
| 5 | +tags: |
| 6 | + - Installation |
| 7 | + - CATM1 |
| 8 | + - NBIOT |
| 9 | +author: 'Benjamin Dannegård' |
| 10 | +hardware: |
| 11 | + - hardware/04.pro/boards/portenta-h7 |
| 12 | + - hardware/04pro/carriers/portenta-max-carrier |
| 13 | + - _snippets/hardware/sim-card |
| 14 | +software: |
| 15 | + - ide-v1 |
| 16 | + - ide-v2 |
| 17 | + - web-editor |
| 18 | +--- |
| 19 | + |
| 20 | +## Introduction |
| 21 | + |
| 22 | +The 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. |
| 23 | + |
| 24 | +***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.*** |
| 25 | + |
| 26 | +## Goals |
| 27 | + |
| 28 | +The goals of this project are: |
| 29 | + |
| 30 | +- Learn how to connect the board and the carrier. |
| 31 | +- Connect to the GSM network with Cat-M1 or NB-IoT. |
| 32 | +- Print HTML content in the Serial Monitor. |
| 33 | + |
| 34 | +## Hardware & Software Needed |
| 35 | + |
| 36 | +- Arduino IDE ([online](https://create.arduino.cc/) or [offline](https://www.arduino.cc/en/main/software)). |
| 37 | +- [Portenta H7](https://store.arduino.cc/products/portenta-h7) |
| 38 | +- Antenna with GSM 850 / 900 / 1800 / 1900 MHz range and the ability to connect via SMA |
| 39 | +- DC 4.5-20V power supply with barrel jack. |
| 40 | +- [Portenta Max carrier](https://store.arduino.cc/products/portenta-max-carrier) |
| 41 | + |
| 42 | +## Instructions |
| 43 | + |
| 44 | +### Circuit |
| 45 | + |
| 46 | +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 Portenta Max Carrier. Press firmly to let it snap in. Once attached, plug the Portenta H7 into your computer using a USB C cable. |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +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. |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | +After everything else is connected, connect a power cable to the barrel jack. The one right next to the SMA antenna connector. |
| 55 | + |
| 56 | +### Arduino IDE |
| 57 | + |
| 58 | +In the Arduino IDE, make sure you have the latest **Portenta mbed os Core** installed. Found in **Tools > Board: > boards manager...**. |
| 59 | + |
| 60 | +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. |
| 61 | + |
| 62 | +### NB-IoT or Cat-M1 |
| 63 | + |
| 64 | +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. |
| 65 | + |
| 66 | +### Switching Between NB-IoT and Cat-M1 |
| 67 | + |
| 68 | +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. |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | +### Programming the Board |
| 73 | + |
| 74 | +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. |
| 75 | + |
| 76 | +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. |
| 77 | + |
| 78 | +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 **example.org**. |
| 79 | + |
| 80 | +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. |
| 81 | + |
| 82 | +### Result of Sketch |
| 83 | + |
| 84 | +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. |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | +### Full Sketch |
| 89 | + |
| 90 | +```cpp |
| 91 | + |
| 92 | +// libraries |
| 93 | +#include <MKRNB.h> |
| 94 | + |
| 95 | +#include "arduino_secrets.h" |
| 96 | +// Please enter your sensitive data in the Secret tab or arduino_secrets.h |
| 97 | +// PIN Number |
| 98 | +const char PINNUMBER[] = SECRET_PINNUMBER; |
| 99 | + |
| 100 | +// initialize the library instance |
| 101 | +NBClient client; |
| 102 | +GPRS gprs; |
| 103 | +NB nbAccess; |
| 104 | + |
| 105 | +// URL, path and port (for example: example.org) |
| 106 | +char server[] = "example.org"; |
| 107 | +char path[] = "/"; |
| 108 | +int port = 80; // port 80 is the default for HTTP |
| 109 | + |
| 110 | +void setup() { |
| 111 | + // initialize serial communications and wait for port to open: |
| 112 | + Serial.begin(9600); |
| 113 | + while (!Serial) { |
| 114 | + ; // wait for serial port to connect. Needed for native USB port only |
| 115 | + } |
| 116 | + |
| 117 | + Serial.println("Starting Arduino web client."); |
| 118 | + // connection state |
| 119 | + boolean connected = false; |
| 120 | + |
| 121 | + // After starting the modem with NB.begin() |
| 122 | + // attach to the GPRS network with the APN, login and password |
| 123 | + while (!connected) { |
| 124 | + if ((nbAccess.begin(PINNUMBER) == NB_READY) && |
| 125 | + (gprs.attachGPRS() == GPRS_READY)) { |
| 126 | + connected = true; |
| 127 | + } else { |
| 128 | + Serial.println("Not connected"); |
| 129 | + delay(1000); |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + Serial.println("connecting..."); |
| 134 | + |
| 135 | + // if you get a connection, report back via serial: |
| 136 | + if (client.connect(server, port)) { |
| 137 | + Serial.println("connected"); |
| 138 | + // Make a HTTP request: |
| 139 | + client.print("GET "); |
| 140 | + client.print(path); |
| 141 | + client.println(" HTTP/1.1"); |
| 142 | + client.print("Host: "); |
| 143 | + client.println(server); |
| 144 | + client.println("Connection: close"); |
| 145 | + client.println(); |
| 146 | + } else { |
| 147 | + // if you didn't get a connection to the server: |
| 148 | + Serial.println("connection failed"); |
| 149 | + } |
| 150 | +} |
| 151 | + |
| 152 | +void loop() { |
| 153 | + // if there are incoming bytes available |
| 154 | + // from the server, read them and print them: |
| 155 | + if (client.available()) { |
| 156 | + Serial.print((char)client.read()); |
| 157 | + } |
| 158 | + |
| 159 | + // if the server's disconnected, stop the client: |
| 160 | + if (!client.available() && !client.connected()) { |
| 161 | + Serial.println(); |
| 162 | + Serial.println("disconnecting."); |
| 163 | + client.stop(); |
| 164 | + |
| 165 | + // do nothing forevermore: |
| 166 | + for (;;) |
| 167 | + ; |
| 168 | + } |
| 169 | +} |
| 170 | +``` |
| 171 | + |
| 172 | +### Troubleshoot |
| 173 | + |
| 174 | +If the code is not working, there are some common issues we can troubleshoot: |
| 175 | + |
| 176 | +- We have entered the wrong pin number. |
| 177 | +- We are out of coverage (no signal). You can run the example sketch **Scan available networks** to see if there is coverage. |
| 178 | +- SIM card may not be activated. |
| 179 | + |
| 180 | +## Next Step |
| 181 | + |
| 182 | +- The Portenta Max Carrier offers a lot of features when used with the Portenta H7. If you want to learn more about the Portenta Max Carriers peripherals and features, check out our [Getting Started guide for Max Carrier and Portenta H7](/tutorials/getting-started-with-H7). |
| 183 | + |
| 184 | +- If you are interested in trying out more of the Max Carriers connectivity options. Be sure to check out our tutorial on how to use [LoRa with the Max Carrier and Portenta H7](/tutorials/lora-tutorial). |
| 185 | + |
| 186 | +## Conclusion |
| 187 | + |
| 188 | +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. |
0 commit comments