LTE Cat M1/NB-IoT Shield Hookup Guide
Example 0: Network Registration
The first example in this tutorial is the most critical. Here we demonstrate how to configure your LTE Shield's SARA-R4 module to communicate with your network of choice. This is a configuration that usually only needs to happen once. After you've successfully run this sketch, your Arduino should be all set up for SMS and TCP/IP messaging.
To begin, load up this example by going to File > Examples > SparkFun_LTE_Shield_Arduino_Library > 00_Register_Operator.
Before uploading the sketch, you may need to adjust the value of MOBILE_NETWORK_OPERATOR
and APN
. The first variable, sent as a parameter to lte.setNetwork
, defines the mobile network operator your LTE shield should configure itself to communicate with. It should be one of the below values:
language:c
// Network operator can be set to either:
// MNO_SW_DEFAULT -- DEFAULT
// MNO_ATT -- AT&T
// MNO_VERIZON -- Verizon
// MNO_TELSTRA -- Telstra
// MNO_TMO -- T-Mobile
const mobile_network_operator_t MOBILE_NETWORK_OPERATOR = MNO_SW_DEFAULT;
const String MOBILE_NETWORK_STRINGS[] = {"Default", "SIM_ICCD", "AT&T", "VERIZON",
"TELSTRA", "T-Mobile", "CT"};
Your access point name (APN), is provided by your SIM card provider. If you're using a Hologram SIM, this should be a string'ed "hologram"
. This value is provided to the lte.setAPN()
function.
language:c
// APN -- Access Point Name. Gateway between GPRS MNO
// and another computer network. E.g. \"hologram\"
const String APN = "hologram";
After uploading the sketch, open up your serial monitor to check the status of your shield's registration. This example is interactive. After possible network operators are scanned, you'll need to enter one of a handful of options to attempt connecting to that operator.
You'll need to be a little patient after uploading this sketch. Depending on the state of your shield, it can take about 30 seconds for the sketch to initialize your shield. It can also take up to three minutes for the shield to scan for network operators in its area.
Some times your choice of network operator will be limited to a set of numerical-only options -- a combination of mobile country codes (MMC) and mobile network codes (MNC). For example, AT&T in the example above is an MCC/MNC combination of 310 and 410, respectively -- that's the operator we select. ("313 100" is an AT&T First Responders Network and "310 260" is T-Mobile.)
Notes on Mobile Country Codes (MCC) and Mobile Network Codes (MNC)
Sometimes your choice of network operator will be limited to a set of numerical-only options. This will be a combination of mobile country codes (MCC) and mobile network codes (MNC). For example, AT&T in the example above is an MCC/MNC combination of 310 and 410, respectively – that’s the operator we select. (“313 100” is an AT&T First Responders Network and “310 260” is T-Mobile.)
If you need to do some digging to discover which MMC/MNC is which, check out the searchable, comprehensive list at mcc-mnc.com and/or The Roaming Zone.
Note: if you leave a region covered by a pair of country/network codes, you may need to reconfigure your shield using this sketch.
What's Going On at Start-Up
The LTE Shield can take a handful of seconds to start up if you've just plugged it in and haven't triggered the power button.
As it initializes communication with the shield, the Arduino library must attempt to verify that the shield is on while also tuning the baud rate down from a potentially unknown baud rate (though, most likely, 115200 bps) to 9600 bps.
On start-up, the library will cycle through the SARA-R4's supported baud rates, and attempt to establish communication. This process may take up to 5 seconds. If the shield doesn't respond, the library will assume it's powered off. It will cycle the POWER button, then start the "autobaud" process over again.
In all, this process can take up to 30 seconds. You should end up with a SARA-R4 module configured at 9600 baud, and ready to begin LTE'ing.
Note: You can shorten this initial power-on time by manually turning on the SARA-R4's power (hold the POWER button down for ~3 seconds).
Initializing the LTE Shield Library
There are a few declarations and function calls you'll need in every LTE Shield library sketch.
Global Definitions
There's, of course, the library include statement:
language:c
#include <SparkFun_LTE_Shield_Arduino_Library.h>
If you're using a software serial port -- as the examples demonstrate -- you'll also need to define a SoftwareSerial
object with RX on pin 8 and TX on pin 9:
language:c
// We need to pass a Serial or SoftwareSerial object to the LTE Shield
// library. Below creates a SoftwareSerial object on the standard LTE
// Shield RX/TX pins:
SoftwareSerial lteSerial(8, 9);
And, finally, you'll need to declare an LTE_Shield
object, which we'll use throughout the sketch for SMS-sending, and TCP/IP interactions. This object optionally takes two parameters -- the POWER and RESET Arduino pins. By default these parameters should match the shield defaults, so they are not usually required.
language:c
// Create a LTE_Shield object to be used throughout the sketch:
#define POWER_PIN 5
#define RESET_PIN 6
LTE_Shield lte(POWER_PIN, RESET_PIN);
Setup Requirements
With your global variables declared, initializing the shield library is as simple as calling lte.begin(SerialPort)
. SerialPort should either be the SoftwareSerial port you declared in globals, or a hardware serial port if that's supported by your Arduino board.
begin()
will return true
on a successful initialization of the shield or false
if communication with the SARA-R4 module fails.
The examples in this library all assume a software serial port on pins 8 and 9. So the begin statement below should work.
language:c
if ( lte.begin(lteSerial) ) {
Serial.println("Successfully initialized the LTE shield via software serial!");
}
If, on the other hand, you're using a hardware serial port (on pins 0/1) to communicate with the shield, the begin statement below may be used:
language:c
if ( lte.begin(Serial1) ) {
Serial.println("Initialied SARA-R4 module on a hardware serial port.");
}
The library will take care of all the begin()
, write()
, and read()
functions provided by your serial port.