Skip to content

Arduino Examples

The SparkFun u-blox Cellular Arduino Library includes a large set of examples to do all sorts of things with supported u-blox cellular modules. Some examples work with all modules, others are limited to specific ones. All examples assume a serial connection between a microcontroller and the LTE Stick (or other supported cellular module) as demonstrated in the Hardware Assembly section. These examples build upon each other so we recommend following them in sequential order to get everything set up and working properly.

LARA-R6 Power

Make sure to power on the module using the "ON" button

If you have not used m-center or AT commands to configure the network information and register the network operator for your device before using this library, you may need to go through Example 2 - Network Info and Example 3 - Register Operator to get the LARA-R6 registered and configured properly on your network. Otherwise, feel free to skip ahead to the Ping and other more complex examples.

Example 1 - Device Identification

The first example performs the basic AT commands to return the device information of a connected module:

  • Manufacturer ID
  • Model
  • Firmware Version
  • Serial Number
  • IMEI ID
  • IMSI ID
  • SIM CCID
  • Subscriber Number (from the SIM)
  • Capabilities
  • SIM state

Open the example by navigating to File < Examples < SparkFun u-blox Cellular Arduino Library < Example 1 - Device Identification or copy the code below into a blank sketch.

Example 1 - Device Information
#include "SparkFun_u-blox_Cellular_Arduino_Library.h"

// Uncomment the line below that you need for Serial on your platform
#define mySerial Serial1
// SoftwareSerial mySerial(16, 17);

// Uncomment the module you're using. If your module is not listed below, then
// it's not supported for this example
SparkFun_ublox_Cellular myModule; // This example works with all modules, so the base class can be used
// SparkFun_ublox_SARA_R5 myModule; // Base SARA-R5 class
// SparkFun_ublox_SARA_R500S myModule;
// SparkFun_ublox_SARA_R500S_01B myModule;
// SparkFun_ublox_SARA_R500S_61B myModule;
// SparkFun_ublox_SARA_R510M8S_61B myModule;
// SparkFun_ublox_SARA_R510S myModule;
// SparkFun_ublox_LARA_R6 myModule; // Base LARA-R6 class
// SparkFun_ublox_LARA_R6001 myModule;
// SparkFun_ublox_LARA_R6001D myModule;
// SparkFun_ublox_LARA_R6401 myModule;
// SparkFun_ublox_LARA_R6401D myModule;
// SparkFun_ublox_LARA_R6801_00B myModule;
// SparkFun_ublox_LARA_R6801D myModule;

// Map SIM states to more readable strings
String simStateString[] = {
    "Not present",     // 0
    "PIN needed",      // 1
    "PIN blocked",     // 2
    "PUK blocked",     // 3
    "Not operational", // 4
    "Restricted",      // 5
    "Operational"      // 6
};

// processSIMstate is provided to the u-blox cellular library via a
// callback setter -- setSIMstateReadCallback. (See setup())
void processSIMstate(UBX_CELL_sim_states_t state)
{
    Serial.println();
    Serial.print(F("SIM state:           "));
    Serial.print(String(state));
    Serial.println();
}

void setup()
{
    Serial.begin(115200); // Start the serial console

    // Wait for user to press key to begin
    Serial.println(F("u-blox Cellular Example 1 - Device Identification"));
    Serial.println(F("Press any key to begin"));

    while (!Serial.available()) // Wait for the user to press a key (send any serial character)
        ;
    while (Serial.available()) // Empty the serial RX buffer
        Serial.read();

    Serial.println(F("Beginning..."));

    // myModule.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial

    // For the MicroMod Asset Tracker, we need to invert the power pin so it pulls high instead of low
    // Uncomment the next line if required
    // myModule.invertPowerPin(true);

    // Initialize the module
    if (myModule.begin(mySerial, UBX_CELL_DEFAULT_BAUD_RATE))
    {
        Serial.println(F("Module connected!"));
    }
    else
    {
        Serial.println(F("Unable to communicate with the module."));
        Serial.println(F("Manually power-on (hold the module's On button for 3 seconds) and try again."));
        while (1)
            ; // Loop forever on fail
    }
    Serial.println();

    Serial.println("Manufacturer ID:     " + String(myModule.getManufacturerID()));
    Serial.println("Model ID:            " + String(myModule.getModelID()));
    Serial.println("Firmware Version:    " + String(myModule.getFirmwareVersion()));
    Serial.println("Product Serial No.:  " + String(myModule.getSerialNo()));
    Serial.println("IMEI:                " + String(myModule.getIMEI()));
    Serial.println("IMSI:                " + String(myModule.getIMSI()));
    Serial.println("SIM CCID:            " + String(myModule.getCCID()));
    Serial.println("Subscriber No.:      " + String(myModule.getSubscriberNo()));
    Serial.println("Capabilities:        " + String(myModule.getCapabilities()));

    // Set a callback to return the SIM state once requested
    myModule.setSIMstateReportCallback(&processSIMstate);
    // Now enable SIM state reporting for states 0 to 6 (by setting the reporting mode LSb)
    if (myModule.setSIMstateReportingMode(1) == UBX_CELL_SUCCESS)
        Serial.println("SIM state reports requested...");
    // You can disable the SIM staus reports again by calling assetTracker.setSIMstateReportingMode(0)
}

void loop()
{
    myModule.poll(); // Keep processing data from the module so we can extract the SIM status
}

Serial Port Selection

This and all following examples default to use Serial1 for serial communication between the LTE Stick and microcontroller. If your selected microcontroller does not have this serial port, uncomment the following line and, if necessary, adjust the pins set for software serial depending on the software serial library limitations.

    // SoftwareSerial mySerial(16, 17);

Select your board (SparkFun Thing Plus ESP32 if you're following along with this tutorial verbatim) and Port and click the "Upload" button. When the code finishes compiling and uploading, open the serial monitor with the baud set to 115200. The code waits on a user prompt to begin so press any key when prompted in the serial monitor and you should see the device information and SIM status print out.

Example 2 - Network Info

The second example verifies the LARA-R6 is receiving an LTE signal on a selected network and prints out the network information and IDs. The code creates the LARA-R6 object and assigns a network operator value.

Example 2 -Network Info
#include "SparkFun_u-blox_Cellular_Arduino_Library.h"

// Uncomment the line below that you need for Serial on your platform
#define mySerial Serial1
// SoftwareSerial mySerial(16, 17);

// Uncomment the module you're using. If your module is not listed below, then
// it's not supported for this example
SparkFun_ublox_Cellular myModule; // This example works with all modules, so the base class can be used
// SparkFun_ublox_SARA_R5 myModule; // Base SARA-R5 class
// SparkFun_ublox_SARA_R500S myModule;
// SparkFun_ublox_SARA_R500S_01B myModule;
// SparkFun_ublox_SARA_R500S_61B myModule;
// SparkFun_ublox_SARA_R510M8S_61B myModule;
// SparkFun_ublox_SARA_R510S myModule;
// SparkFun_ublox_LARA_R6 myModule; // Base LARA-R6 class
// SparkFun_ublox_LARA_R6001 myModule;
// SparkFun_ublox_LARA_R6001D myModule;
// SparkFun_ublox_LARA_R6401 myModule;
// SparkFun_ublox_LARA_R6401D myModule;
// SparkFun_ublox_LARA_R6801_00B myModule;
// SparkFun_ublox_LARA_R6801D myModule;

// Map registration status messages to more readable strings
String registrationString[] = {
    "Not registered",                        // 0
    "Registered, home",                      // 1
    "Searching for operator",                // 2
    "Registration denied",                   // 3
    "Registration unknown",                  // 4
    "Registered, roaming",                   // 5
    "Registered, home (SMS only)",           // 6
    "Registered, roaming (SMS only)",        // 7
    "Registered, emergency service only",    // 8
    "Registered, home, CSFB not preferred",  // 9
    "Registered, roaming, CSFB not prefered" // 10
};

// If you are based in Europe, you will (probably) need to select MNO_STD_EUROPE
const mobile_network_operator_t MOBILE_NETWORK_OPERATOR = MNO_GLOBAL;

void setup()
{
    Serial.begin(115200); // Start the serial console

    // Wait for user to press key to begin
    Serial.println(F("u-blox Cellular Example 2 - Network Info"));
    Serial.println(F("Press any key to begin"));

    while (!Serial.available()) // Wait for the user to press a key (send any serial character)
        ;
    while (Serial.available()) // Empty the serial RX buffer
        Serial.read();

    Serial.println(F("Beginning..."));

    // myModule.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial

    // For the MicroMod Asset Tracker, we need to invert the power pin so it pulls high instead of low
    // Uncomment the next line if required
    // myModule.invertPowerPin(true);

    // Initialize the module
    if (myModule.begin(mySerial, UBX_CELL_DEFAULT_BAUD_RATE))
    {
        Serial.println(F("Module connected!"));
    }
    else
    {
        Serial.println(F("Unable to communicate with the module."));
        Serial.println(F("Manually power-on (hold the module's On button for 3 seconds) and try again."));
        while (1)
            ; // Loop forever on fail
    }
    Serial.println();

    if (!myModule.setNetworkProfile(MOBILE_NETWORK_OPERATOR))
    {
        Serial.println(F("Error setting network. Try cycling the power."));
        while (1)
            ;
    }

    Serial.println(F("Network profile set. Ready to go!"));

    // RSSI: Received signal strength:
    Serial.println("RSSI: " + String(myModule.rssi()));
    // Registration Status
    int regStatus = myModule.registration();
    if ((regStatus >= 0) && (regStatus <= 10))
    {
        Serial.println("Network registration: " + registrationString[regStatus]);
    }

    // Print the Context IDs, Access Point Names and IP Addresses
    Serial.println(F("Available PDP (Packet Data Protocol) APNs (Access Point Names) and IP Addresses:"));
    Serial.println(F("Context ID:\tAPN Name:\tIP Address:"));
    for (int cid = 0; cid < UBX_CELL_NUM_PDP_CONTEXT_IDENTIFIERS; cid++)
    {
        String apn = "";
        IPAddress ip(0, 0, 0, 0);
        myModule.getAPN(cid, &apn, &ip);
        if (apn.length() > 0)
        {
            Serial.print(cid);
            Serial.print(F("\t\t"));
            Serial.print(apn);
            Serial.print(F("\t"));
            Serial.println(ip);
        }
    }

    Serial.println();

    if (regStatus > 0)
    {
        Serial.println(F("All set. Go to the next example!"));
    }
}

void loop()
{
    // Do nothing. Now that we're registered move on to the next example.
}

After uploading the code, open a terminal window with the baud set to 115200 and enter any key to start the example. After initializing everything needed, the code attempts to set the Network Profile to the Mobile Network Operator entered. If successful, the code prints out the RSSI (Received Signal Strength), Network Registration Status and Context IDs, Access Point Names and IP Addresses.

Example 3 - Register Operator

Example 4 checks to see if the LARA-R6 is connected to a network and lets you register on a different network if available and if the SIM supports this. This example can also be used to list all the LTE operators the LARA-R6 can detect. Note, you can only connect to networks supported by your SIM card. Refer to your SIM card manufacturer's documentation for supported networks.

Example 3 - Register Operator
#include "SparkFun_u-blox_Cellular_Arduino_Library.h"

// Uncomment the line below that you need for Serial on your platform
#define mySerial Serial1
// SoftwareSerial mySerial(16, 17);

// Uncomment the module you're using. If your module is not listed below, then
// it's not supported for this example
SparkFun_ublox_Cellular myModule; // This example works with all modules, so the base class can be used
// SparkFun_ublox_SARA_R5 myModule; // Base SARA-R5 class
// SparkFun_ublox_SARA_R500S myModule;
// SparkFun_ublox_SARA_R500S_01B myModule;
// SparkFun_ublox_SARA_R500S_61B myModule;
// SparkFun_ublox_SARA_R510M8S_61B myModule;
// SparkFun_ublox_SARA_R510S myModule;
// SparkFun_ublox_LARA_R6 myModule; // Base LARA-R6 class
// SparkFun_ublox_LARA_R6001 myModule;
// SparkFun_ublox_LARA_R6001D myModule;
// SparkFun_ublox_LARA_R6401 myModule;
// SparkFun_ublox_LARA_R6401D myModule;
// SparkFun_ublox_LARA_R6801_00B myModule;
// SparkFun_ublox_LARA_R6801D myModule;

// Map registration status messages to more readable strings
String registrationString[] = {
    "Not registered",                        // 0
    "Registered, home",                      // 1
    "Searching for operator",                // 2
    "Registration denied",                   // 3
    "Registration unknown",                  // 4
    "Registered, roaming",                   // 5
    "Registered, home (SMS only)",           // 6
    "Registered, roaming (SMS only)",        // 7
    "Registered, emergency service only",    // 8
    "Registered, home, CSFB not preferred",  // 9
    "Registered, roaming, CSFB not prefered" // 10
};

// If you are based in Europe, you will (probably) need to select MNO_STD_EUROPE
const mobile_network_operator_t MOBILE_NETWORK_OPERATOR = MNO_GLOBAL;

const String MOBILE_NETWORK_STRINGS[] = {"default (Undefined/Regulatory)",
                                         "SIM ICCID",
                                         "AT&T",
                                         "Verizon",
                                         "Telstra",
                                         "T-Mobile US",
                                         "China Telecom",
                                         "Sprint",
                                         "Vodafone",
                                         "NTT DoCoMo",
                                         "Telus",
                                         "SoftBank",
                                         "Deutsche Telekom",
                                         "US Cellular",
                                         "SKT",
                                         "global (factory default)",
                                         "standard Europe",
                                         "standard Europe No-ePCO",
                                         "NOT RECOGNIZED"};

// Convert the operator number into an index for MOBILE_NETWORK_STRINGS
int convertOperatorNumber(mobile_network_operator_t mno)
{
    switch (mno)
    {
    case 0:
    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
        return ((int)mno);
    case 8:
        return 7;
    case 19:
        return 8;
    case 20:
        return 9;
    case 21:
        return 10;
    case 28:
        return 11;
    case 31:
        return 12;
    case 32:
        return 13;
    case 39:
        return 14;
    case 90:
        return 15;
    case 100:
        return 16;
    case 101:
        return 17;
    default: // NOT RECOGNIZED
        return 18;
    }
}

// This defines the size of the ops struct array. To narrow the operator
// list, set MOBILE_NETWORK_OPERATOR to AT&T, Verizon etc. instead
// of MNO_SW_DEFAULT.
#define MAX_OPERATORS 10

// Uncomment this line if you want to be able to communicate directly with the module in the main loop
// #define DEBUG_PASSTHROUGH_ENABLED

void setup()
{
    int opsAvailable;
    struct operator_stats ops[MAX_OPERATORS];
    String currentOperator = "";
    bool newConnection = true;

    Serial.begin(115200); // Start the serial console

    // Wait for user to press key to begin
    Serial.println(F("u-blox Cellular Example 3 - Register Operator"));
    Serial.println(F("Press any key to begin"));

    while (!Serial.available()) // Wait for the user to press a key (send any serial character)
        ;
    while (Serial.available()) // Empty the serial RX buffer
        Serial.read();

    Serial.println(F("Beginning..."));

    // myModule.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial

    // For the MicroMod Asset Tracker, we need to invert the power pin so it pulls high instead of low
    // Uncomment the next line if required
    // myModule.invertPowerPin(true);

    // Initialize the module
    if (myModule.begin(mySerial, UBX_CELL_DEFAULT_BAUD_RATE))
    {
        Serial.println(F("Module connected!"));
    }
    else
    {
        Serial.println(F("Unable to communicate with the module."));
        Serial.println(F("Manually power-on (hold the module's On button for 3 seconds) and try again."));
        while (1)
            ; // Loop forever on fail
    }
    Serial.println();

    // First check to see if we're already connected to an operator:
    if (myModule.getOperator(&currentOperator) == UBX_CELL_SUCCESS)
    {
        Serial.print(F("Already connected to: "));
        Serial.println(currentOperator);
        // If already connected provide the option to type y to connect to new operator
        Serial.println(F("Press y to connect to a new operator, or any other key to continue.\r\n"));
        while (!Serial.available())
            ;
        if (Serial.read() != 'y')
        {
            newConnection = false;
        }
        else
        {
            myModule.deregisterOperator(); // Deregister from the current operator so we can connect to a new one
        }
        while (Serial.available())
            Serial.read();
    }

    if (newConnection)
    {
        // Set MNO to either Verizon, T-Mobile, AT&T, Telstra, etc.
        // This will narrow the operator options during our scan later
        Serial.println(F("Setting mobile-network operator"));
        if (myModule.setNetworkProfile(MOBILE_NETWORK_OPERATOR))
        {
            Serial.print(F("Set mobile network operator to "));
            Serial.println(MOBILE_NETWORK_STRINGS[convertOperatorNumber(MOBILE_NETWORK_OPERATOR)] + "\r\n");
        }
        else
        {
            Serial.println(F("Error setting MNO. Try cycling the power. Freezing..."));
            while (1)
                ;
        }

        // Wait for user to press button before initiating network scan.
        Serial.println(F("Press any key scan for networks.."));
        serialWait();

        Serial.println(F("Scanning for networks...this may take up to 3 minutes\r\n"));
        // myModule.getOperators takes in a operator_stats struct pointer and max number of
        // structs to scan for, then fills up those objects with operator names and numbers
        opsAvailable = myModule.getOperators(ops, MAX_OPERATORS); // This will block for up to 3 minutes

        if (opsAvailable > 0)
        {
            // Pretty-print operators we found:
            Serial.println("Found " + String(opsAvailable) + " operators:");
            printOperators(ops, opsAvailable);
            Serial.println(String(opsAvailable + 1) + ": use automatic selection");
            Serial.println();

            // Wait until the user presses a key to initiate an operator connection
            Serial.println("Press 1-" + String(opsAvailable + 1) + " to select an operator.");
            char c = 0;
            bool selected = false;
            while (!selected)
            {
                while (!Serial.available())
                    ;
                c = Serial.read();
                int selection = c - '0';
                if ((selection >= 1) && (selection <= (opsAvailable + 1)))
                {
                    selected = true;
                    Serial.println("Connecting to option " + String(selection));
                    if (selection == (opsAvailable + 1))
                    {
                        if (myModule.automaticOperatorSelection() == UBX_CELL_SUCCESS)
                        {
                            Serial.println("Automatic operator selection: successful\r\n");
                        }
                        else
                        {
                            Serial.println(
                                F("Automatic operator selection: error. Reset and try again, or try another network."));
                        }
                    }
                    else
                    {
                        if (myModule.registerOperator(ops[selection - 1]) == UBX_CELL_SUCCESS)
                        {
                            Serial.println("Network " + ops[selection - 1].longOp + " registered\r\n");
                        }
                        else
                        {
                            Serial.println(
                                F("Error connecting to operator. Reset and try again, or try another network."));
                        }
                    }
                }
            }
        }
        else
        {
            Serial.println(F("Did not find an operator. Double-check SIM and antenna, reset and try again, or try "
                             "another network."));
            while (1)
                ;
        }
    }

    // At the very end print connection information
    printInfo();
}

void loop()
{
    // Loop provides a debugging interface.
    if (mySerial.available())
    {
        Serial.write((char)mySerial.read());
    }
#ifdef DEBUG_PASSTHROUGH_ENABLED
    if (Serial.available())
    {
        mySerial.write((char)Serial.read());
    }
#endif
}

void printInfo(void)
{
    String currentApn = "";
    IPAddress ip(0, 0, 0, 0);
    String currentOperator = "";

    Serial.println(F("Connection info:"));
    Serial.println(F("Context ID:\tAPN Name:\tIP Address:"));
    for (int cid = 0; cid < UBX_CELL_NUM_PDP_CONTEXT_IDENTIFIERS; cid++)
    {
        String apn = "";
        IPAddress ip(0, 0, 0, 0);
        myModule.getAPN(cid, &apn, &ip);
        if (apn.length() > 0)
        {
            Serial.print(cid);
            Serial.print(F("\t\t"));
            Serial.print(apn);
            Serial.print(F("\t"));
            Serial.println(ip);
        }
    }

    // Operator name or number
    if (myModule.getOperator(&currentOperator) == UBX_CELL_SUCCESS)
    {
        Serial.print(F("Operator: "));
        Serial.println(currentOperator);
    }

    // Received signal strength
    Serial.println("RSSI: " + String(myModule.rssi()));
    Serial.println();
}

void printOperators(struct operator_stats *ops, int operatorsAvailable)
{
    for (int i = 0; i < operatorsAvailable; i++)
    {
        Serial.print(String(i + 1) + ": ");
        Serial.print(ops[i].longOp + " (" + String(ops[i].numOp) + ") - ");
        switch (ops[i].stat)
        {
        case 0:
            Serial.print(F("UNKNOWN"));
            break;
        case 1:
            Serial.print(F("AVAILABLE"));
            break;
        case 2:
            Serial.print(F("CURRENT"));
            break;
        case 3:
            Serial.print(F("FORBIDDEN"));
            break;
        }
        switch (ops[i].act)
        {
        case 0:
            Serial.print(F(" - GSM"));
            break;
        case 2:
            Serial.print(F(" - UTRAN"));
            break;
        case 3:
            Serial.print(F(" - GSM/GPRS with EDGE"));
            break;
        case 7:
            Serial.print(F(" - LTE")); // SARA-R5 only supports LTE
            break;
        }
        Serial.println();
    }
    Serial.println();
}

void serialWait()
{
    while (Serial.available())
        Serial.read();
    while (!Serial.available())
        ;
    delay(100);
    while (Serial.available())
        Serial.read();
}

Example 5 - Ping

The eighth example tests the LTE Stick's data connection by a standard server ping. Open a terminal window and follow the prompts then enter a server to ping. Any valid web address like www.google.com or www.sparkfun.com works. If the ping succeeds the code prints out the time to send and receive the ping in milliseconds.

Example 5 - Ping
#include "SparkFun_u-blox_Cellular_Arduino_Library.h"

// Uncomment the line below that you need for Serial on your platform
#define mySerial Serial1
// SoftwareSerial mySerial(16, 17);

// Uncomment the module you're using. If your module is not listed below, then
// it's not supported for this example
SparkFun_ublox_Cellular myModule; // This example works with all modules, so the base class can be used
// SparkFun_ublox_SARA_R5 myModule; // Base SARA-R5 class
// SparkFun_ublox_SARA_R500S myModule;
// SparkFun_ublox_SARA_R500S_01B myModule;
// SparkFun_ublox_SARA_R500S_61B myModule;
// SparkFun_ublox_SARA_R510M8S_61B myModule;
// SparkFun_ublox_SARA_R510S myModule;
// SparkFun_ublox_LARA_R6 myModule; // Base LARA-R6 class
// SparkFun_ublox_LARA_R6001 myModule;
// SparkFun_ublox_LARA_R6001D myModule;
// SparkFun_ublox_LARA_R6401 myModule;
// SparkFun_ublox_LARA_R6401D myModule;
// SparkFun_ublox_LARA_R6801_00B myModule;
// SparkFun_ublox_LARA_R6801D myModule;

String pingMe = ""; // The name of the server we are going to ping

// processPingResult is provided to the u-blox cellular library via a
// callback setter -- setPingCallback. (See the end of setup())
void processPingResult(int retry, int p_size, String remote_hostname, IPAddress ip, int ttl, long rtt)
{
    Serial.println();
    Serial.print(F("Ping Result:  Retry #:"));
    Serial.print(retry);
    Serial.print(F("  Ping Size (Bytes):"));
    Serial.print(p_size);
    Serial.print(F("  Remote Host:\""));
    Serial.print(remote_hostname);
    Serial.print(F("\"  IP Address:\""));
    Serial.print(String(ip[0]));
    Serial.print(F("."));
    Serial.print(String(ip[1]));
    Serial.print(F("."));
    Serial.print(String(ip[2]));
    Serial.print(F("."));
    Serial.print(String(ip[3]));
    Serial.print(F("\"  Time To Live (hops):"));
    Serial.print(ttl);
    Serial.print(F("  Round Trip (ms):"));
    Serial.print(rtt);
    Serial.println();
}

void setup()
{
    String currentOperator = "";

    Serial.begin(115200); // Start the serial console

    // Wait for user to press key to begin
    Serial.println(F("u-blox Cellular Example 5 - Ping"));
    Serial.println(F("Press any key to begin"));

    while (!Serial.available()) // Wait for the user to press a key (send any serial character)
        ;
    while (Serial.available()) // Empty the serial RX buffer
        Serial.read();

    Serial.println(F("Beginning..."));

    // myModule.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial

    // For the MicroMod Asset Tracker, we need to invert the power pin so it pulls high instead of low
    // Uncomment the next line if required
    // myModule.invertPowerPin(true);

    // Initialize the module
    if (myModule.begin(mySerial, UBX_CELL_DEFAULT_BAUD_RATE))
    {
        Serial.println(F("Module connected!"));
    }
    else
    {
        Serial.println(F("Unable to communicate with the module."));
        Serial.println(F("Manually power-on (hold the module's On button for 3 seconds) and try again."));
        while (1)
            ; // Loop forever on fail
    }
    Serial.println();

    // First check to see if we're connected to an operator:
    if (myModule.getOperator(&currentOperator) == UBX_CELL_SUCCESS)
    {
        Serial.print(F("Connected to: "));
        Serial.println(currentOperator);
    }
    else
    {
        Serial.print(F("The module is not yet connected to an operator. Please use the previous examples to connect. "
                       "Or wait and retry. Freezing..."));
        while (1)
            ; // Do nothing more
    }

    Serial.println();
    Serial.println(F("*** Set the Serial Monitor line ending to Newline ***"));

    Serial.println();
    Serial.println(F("Enter the name of the server you want to ping (followed by LF / Newline): "));
    Serial.println(F("Example: \"www.google.com\""));

    // Set a callback to process the Ping result
    myModule.setPingCallback(&processPingResult);
}

void loop()
{
    if (Serial.available())
    {
        char c = Serial.read();
        if (c == '\n')
        {
            // Newline received so let's do that ping!
            Serial.println("Pinging " + pingMe + "...");
            myModule.ping(pingMe); // Use the default parameters

            // Use custom parameters
            // int retries = 4; // number of retries
            // int p_size = 32; // packet size (bytes)
            // unsigned long timeout = 5000; // timeout (ms)
            // int ttl = 32; // Time To Live
            // myModule.ping(pingMe, retries, p_size, timeout, ttl);

            pingMe = ""; // Clear the server name for the next try
        }
        else
        {
            // Add serial characters to the server address
            pingMe += c;
        }
    }

    myModule.poll(); // Keep processing data from the module so we can catch the Ping result
}

If the ping fails, try uncommenting this line that enables debugging over serial:

// myModule.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial

Upload the code again, retry the ping and look for any messages that include +UUPINGER:. Refer to the list of Ping error codes in Appendix A. 9 of the AT Command Reference to decipher the error code.

Further Examples

These examples perform the basic tests for making sure everything is working properly on the LTE Stick but the SparkFun u-blox Cellular Arduino Library includes many more examples to take full advantage of the LARA-R6's capabilities including audio examples for playing audio tones and phonecall control. The audio examples require external hardware including an audio codec and are beyond the scope of this tutorial.