# SODAQ SARA R41XM

Get started with the SODAQ SARA R410M/R412M SFF or AFF, an Arduino-based development board with an embedded u-blox SARA R41X LTE-M, NB-IoT and GPRS modem. The device comes with an integrated GPS, Accelerometer and Magnetometer.

![](https://3922449203-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M0mPxGpottOEfcucXOR%2Fuploads%2FR7i0KGKvKhSxeXQaN4Hi%2FSODAQ%20SARA%20%26%20Monogoto.jpg?alt=media\&token=9cce1cb4-a4e4-4404-9c3f-4d9f5c2a989b)

### Quick Navigation

* [Getting Started with the SODAQ SARA](https://docs.monogoto.io/getting-started/general-device-configurations/iot-devices/u-blox-sara-r4/broken-reference)
* [Connect the u-blox to Monogoto](https://docs.monogoto.io/getting-started/general-device-configurations/iot-devices/u-blox-sara-r4)
* [Build an end-to-end tracking application](#trackingapplication)
* [Useful links](#useful-link)

### Prerequisites

* Monogoto SIM
* [SODAQ SARA R412M](https://shop.sodaq.com/sodaq-sara-aff-r412m.html) / [R410M](#prerequisites)
* [Arduino IDE](https://www.arduino.cc/en/software)

## **Getting Started with the SODAQ SARA** <a href="#gettingstarted" id="gettingstarted"></a>

### **Install SODAQ SARA board manager**

Open up the Arduino IDE and select ***Arduino*****&#x20;>&#x20;*****Preferences*** from the menu bar. Paste the following URL in the field next to **Additional Boards Manager URLs**:

`http://downloads.sodaq.net/package_sodaq_samd_index.json`

![](https://3922449203-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M0mPxGpottOEfcucXOR%2Fuploads%2FxIEwoPtpeM7WMuF6A8Xf%2FAdditional%20Boards%20Manager.png?alt=media\&token=76e1528c-ffc4-401d-b97f-3b79e43c5e48)

Go to ***Tools > Board > Board Manager***, search for **SODAQ SAMD** and install the latest version.

![](https://3922449203-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M0mPxGpottOEfcucXOR%2Fuploads%2FR8Hn5GsNnQI5g2RsbGLd%2Fboard%20manager.png?alt=media\&token=ce719776-0ce0-477e-b3ff-4ebc4f76c246)

### **Upload Passthrough sketch**

*The Passthrough sketch allows you to send AT commands to the u-blox modem.*

![Arduino SARA AFF](https://3922449203-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M0mPxGpottOEfcucXOR%2Fuploads%2FnovjywwE02JxwWm8wsjr%2FSODAQ%20SARA%20info.jpg?alt=media\&token=4ddbc44c-3b72-41e3-87f5-052a53c12cf7) ![Arduino SARA SFF](https://3922449203-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M0mPxGpottOEfcucXOR%2Fuploads%2Fwqs0B4XKKyRzCRcmlHQE%2FSODAQ%20SFF.jpg?alt=media\&token=69ff8b38-df69-420f-ada7-3c741c52856b)

Start by connecting the **LTE antenna**

Add the **Monogoto SIM**

Connect the **battery**

Connect the SODAQ SARA to your computer using the **micro USB port next to the SIM card slot**, an LED will light up <mark style="color:yellow;">**yellow**</mark>.

{% hint style="warning" %}
Make sure to connect the USB cable to the micro USB port next to the SIM card slot. When connecting the cable to the second USB port it is not possible to upload the Arduino sketch. &#x20;
{% endhint %}

Select the right board in the Arduino IDE via ***Tools > Board > SODAQ SAMD Boards > SODAQ SARA AFF/SFF***

Select the right port via ***Tools > Port***

<details>

<summary>SODAQ SARA <mark style="color:red;">AFF</mark> passthrough Arduino Sketch:</summary>

```arduino
// Passthrough Arduino sketch
// Source: https://learn.sodaq.com/Boards/Sara_AFF/Examples/passthrough/

#include <Arduino.h>

#define R4XX // Comment out when you use the u-blox R2XX module

#if defined(ARDUINO_SODAQ_SARA)
#define DEBUG_STREAM SerialUSB
#define MODEM_STREAM Serial1
#define powerPin SARA_ENABLE
#define enablePin SARA_TX_ENABLE

#else
#error "Please select the SODAQ SARA as your board via Tools > Board:"
#endif

#if defined(R4XX)
unsigned long baud = 115200;  //start at 115200 allow the USB port to change the Baudrate
#else
unsigned long baud = 9600;  //start at 9600 allow the USB port to change the Baudrate
#endif

void setup()
{
#ifdef powerPin
  // Turn the nb-iot module on
  pinMode(powerPin, OUTPUT);
  digitalWrite(powerPin, HIGH);
#endif

#ifdef enablePin
  // Set state to active
  pinMode(enablePin, OUTPUT);
  digitalWrite(enablePin, HIGH);
#endif // enablePin

#if defined(R4XX)
    pinMode(SARA_R4XX_TOGGLE, OUTPUT);
    digitalWrite(SARA_R4XX_TOGGLE, LOW);
    delay(2000);
    pinMode(SARA_R4XX_TOGGLE, INPUT);
#endif

  // Start communication
  DEBUG_STREAM.begin(baud);
  MODEM_STREAM.begin(baud);
}

// Forward every message to the other serial
void loop()
{
  while (DEBUG_STREAM.available())
  {
    MODEM_STREAM.write(DEBUG_STREAM.read());
  }

  while (MODEM_STREAM.available())
  {
    DEBUG_STREAM.write(MODEM_STREAM.read());
  }

  // check if the USB virtual serial wants a new baud rate
  // This will be used by the UEUpdater to flash new software
  if (DEBUG_STREAM.baud() != baud) {
    baud = DEBUG_STREAM.baud();
    MODEM_STREAM.begin(baud);
  }
}
```

</details>

<details>

<summary>SODAQ SARA <mark style="color:red;">SFF</mark> passthrough Arduino Sketch:</summary>

```
// Passthrough Arduino sketch
// Source: https://learn.sodaq.com/Boards/Sara_SFF/examples/passthrough/

#include <Arduino.h>

#define R4XX // Comment out when you use the u-blox R3XX or R2XX module
//#define N3XX // Uncomment when you use the ublox N3XX module

#define DEBUG_STREAM SerialUSB
#define MODEM_STREAM Serial1

#if defined(R4XX)
unsigned long baud = 115200;  //start at 115200 allow the USB port to change the Baudrate
#elif defined(N3XX)
unsigned long baud = 57600;  //start at 57600 allow the USB port to change the Baudrate
#else
unsigned long baud = 9600;  //start at 9600 allow the USB port to change the Baudrate
#endif

void setup()
{
  // Turn the power to the SARA module on.
  // we have a powerswitch on board to switch the power to the SARA on/of when needed
  // in most applications we keep the power on all the time  
  pinMode(SARA_ENABLE, OUTPUT);  
  digitalWrite(SARA_ENABLE, HIGH);

#if defined(R4XX) || defined(N3XX)
    // Turn the nb-iot module on
    // The R4XX module has an on/off pin. You can toggle this pin or keep it low to
    // switch on the module
    pinMode(SARA_R4XX_TOGGLE, OUTPUT);
    digitalWrite(SARA_R4XX_TOGGLE, LOW);
    delay(2000);
    pinMode(SARA_R4XX_TOGGLE, INPUT);
#endif

  // Start communication
  DEBUG_STREAM.begin(baud);
  MODEM_STREAM.begin(baud);
}

// Forward every message to the other serial
void loop()
{
  while (DEBUG_STREAM.available())
  {
    MODEM_STREAM.write(DEBUG_STREAM.read());
  }

  while (MODEM_STREAM.available())
  {
    DEBUG_STREAM.write(MODEM_STREAM.read());
  }

  // check if the USB virtual serial wants a new baud rate
  // This will be used by the UEUpdater to flash new software
  if (DEBUG_STREAM.baud() != baud) {
    baud = DEBUG_STREAM.baud();
    MODEM_STREAM.begin(baud);
  }
}

```

</details>

### **Establish a connection with the u-blox modem**

**Open up the Serial Monitor** from the Arduino IDE by clicking the Serial Monitor-button in the top right corner.

![](https://3922449203-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M0mPxGpottOEfcucXOR%2Fuploads%2FPQjsyHIULl10LJCwBfq4%2FSerial%20Monitor.png?alt=media\&token=8d013a1e-1142-456e-980e-0a202e343e10)

Set the baud rate to **115200** and enter `AT` in the Serial Monitor. If the connection with the u-blox modem has been established, the board will answer with `OK`.

![](https://3922449203-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M0mPxGpottOEfcucXOR%2Fuploads%2FV6s6KVVyaais3T7zV1Cq%2Fat%20-%20OK.png?alt=media\&token=b9effb72-ea3b-48ab-8d1b-908441f29013)

{% hint style="warning" %}
If you don’t see <mark style="color:red;">`OK`</mark> click the reset button on the SODAQ SARA and try again.
{% endhint %}

Next up, disable PSM (Power Saving Mode) and eDRX (Extended Discontinuous Reception). When these features are enabled the modeqm goes to sleep automatically and stops responding to AT Commands.

Disable PSM:

```arduino
AT+CPSMS=0
```

Disable eDRX:

```arduino
AT+CEDRXS=0
```

Disable Power saving control:

```arduino
AT+UPSV=0
```

![](https://3922449203-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M0mPxGpottOEfcucXOR%2Fuploads%2FsBaHPfHERan5S9VuAMfO%2Fdisable%20power%20saving.png?alt=media\&token=3dbe0b99-22c5-4390-81fb-a94870996c77)

## **Connect the u-blox modem to Monogoto** <a href="#ublox-connect" id="ublox-connect"></a>

Visit the u-blox SARA R4 documentation for a detailed guide on connecting the modem to Monogoto.

{% content-ref url="" %}
[](https://docs.monogoto.io/getting-started/general-device-configurations/iot-devices/u-blox-sara-r4)
{% endcontent-ref %}

## Build an end-to-end tracking application <a href="#trackingapplication" id="trackingapplication"></a>

Guard your valuable assets, get notified if any assets move without your consent and keep track of their real-time GPS location.\
\&#xNAN;*Source:* [*AllThingsTalk*](https://www.allthingstalk.com/faq/guard-and-track-your-assets-with-the-lte-m-rdk)

### **Prerequisites**

* Monogoto SIM
* [SODAQ SARA R412M](https://shop.sodaq.com/sodaq-sara-aff-r412m.html) / [R410M](https://shop.sodaq.com/sodaq-sara-aff-r410m.html)
* [Arduino IDE](https://www.arduino.cc/en/software)
* [Account on AllThingsTalk](https://www.allthingstalk.com/)

### Install the AllThingsTalk Arduino library

Open your Arduino IDE and install the `AllThingsTalk LTE-M SDK` library via ***Sketch > Include library > Manage Libraries***.

![](https://3922449203-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M0mPxGpottOEfcucXOR%2Fuploads%2FpmgprZH0ta8nR7IIrzj4%2FATT%20SDK.png?alt=media\&token=958d1045-9e7c-4c9d-809b-0d62cf636d39)

Open the sketch `GuardAndTrackAssets`: ***File > Examples > AllThingsTalk LTE-M SDK > SDK Examples > GuardAndTrackAssets***

### Register your device in AllThingsTalk Maker

Create a [free account on AllThingsTalk](https://www.allthingstalk.com/)

Visit to the [AllThingsTalk Maker portal](https://maker.allthingstalk.com/)

![AllThingsTalk Maker](https://3922449203-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M0mPxGpottOEfcucXOR%2Fuploads%2FSwYD6QS6LyENx3b90la6%2FATT%20maker.png?alt=media\&token=2b3d7738-7a20-4dbd-b90e-69b48d8ce683)

Click the **CONNECT A DEVICE** button and select the **LTE-M Rapid Development Kit**. **Skip** the step for selecting a NB-IoT/LTE-M network provider.

Click on **Settings** and **Authentication** to find your **Device ID** and **Device Token**.&#x20;

![](https://3922449203-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M0mPxGpottOEfcucXOR%2Fuploads%2FR5y0T4tf6BQkR69jXiKQ%2FAuthentication.png?alt=media\&token=3b1295b2-8028-4059-9b6d-d9218d77d524)

In your Arduino sketch click the tab `keys.h`. Add the authentication credentials and update the APN settings to `data.mono`.

![](https://3922449203-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M0mPxGpottOEfcucXOR%2Fuploads%2FeMrc6FRtxEdAVYsikklQ%2FATT-arduino-keys.png?alt=media\&token=f7a4fbe0-c412-442d-8fce-423670af722e)

Upload the sketch to the SODAQ SARA and wait for the onboard LED to turn <mark style="color:green;">**green**</mark>.

> Did the LED turn green? Congratulations! The device is connected to both Monogoto and AllThingsTalk 🙌

### Start tracking your assets

Place your device outside or next to a window so it can receive GPS signals.

Go back to the **AllThingsTalk Maker**, select your asset and click on the actuator **Lock**, scroll down to the section **State** and enter.

```json
{
    "value": "false"
}
```

![](https://3922449203-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M0mPxGpottOEfcucXOR%2Fuploads%2Fq2uSF2qyt4pW69S7hf1p%2FState-false.png?alt=media\&token=848b103f-be4e-4a17-a640-1019119a2275)

Next up, click on the **Lock** actuator again, scroll down to the section **Command** and ente&#x72;**:**

```json
{
    "value": "true"
}
```

When shaking the device, an alert is triggered and the device starts sending GPS data regularly. Visit the **Debug** tab to see the GPS data appear.

![](https://3922449203-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M0mPxGpottOEfcucXOR%2Fuploads%2FECZP3XfVr1sJB5m3wzIR%2Fdata-att.png?alt=media\&token=5d868e44-7ae9-44c9-aeb5-0f583e0da4cc)

> Great work! 👏  You managed to build an end-to-end LTE-M application. You can now start playing around with [widgets](https://www.allthingstalk.com/faq/creating-a-pinboard) to visualize your GPS data in AllThingsTalk or to create [rules](https://www.allthingstalk.com/faq/get-started-with-rules) to trigger actions based on sensor data.

## Useful Link

* [AllThingsTalk documentation](https://www.allthingstalk.com/faq/guard-and-track-your-assets-with-the-lte-m-rdk)
* [u-blox AT commands](https://www.u-blox.com/sites/default/files/SARA-R4_ATCommands_UBX-17003787.pdf)
* [u-blox Product page](https://www.u-blox.com/en/product/sara-r4-series)
* [SODAQ Documentation](https://learn.sodaq.com/Boards/Sara_AFF/)&#x20;
* [SODAQ Shop](https://shop.sodaq.com/sodaq-sara-aff-r412m.html)
