A guide to connecting the Adafruit Feather M0 Lora (US915) to The Things Network using OTAA.
The Adafruit Feather M0 LoRa board consists of an ATSAMD21G18 ARM Cortex M0 microcontroller connected to a HopeRF RFM95 LoRa radio module. This tutorial is for the US915 band. Other bands will not work using these instructions, the differences are significant. The IBM LMIC framework is an Arduino port of the LoRaWAN-in-C framework provided by IBM.
The US915 LoRaWAN band is divided into 72 sub channels. Each gateway uses 8 of these sub channels. The Things Network uses sub channels 8-15. The example sketch demonstrates how to configure the LMIC to easily join any Things Network gateway in the US915 band.
- Solder a 78mm length of wire to the antenna pin.
- Solder 2 jumpers to enable the Feather M0 to function as a LoRaWAN node using LMIC.
- Install the IBM LMIC framework for Arduino.
- Modify the library directly so that it will work in the US915 band and with our specific radio.
- In the example sketch, modify the Device EUI, Application EUI and Application Key parameters taken from The Things Network registration.
- In the example sketch, modify the pin mapping specifically for the Feather M0.
- In the example sketch, add the lines that select the US915 sub band used by TTN gateways.
- Cut 78mm of wire and solder to the pin marked
Ant.
. This is a 1/4 wave dipole for 915MHz. - Solder jumpers as shown in the photo below. Pin 11 to D2. Pin 8 to io1.
In the Arduino IDE Library Manager select and install IBM LMIC framework by IBM Version 1.5.0+arduino-2
These modifications must be done directly in the installed library. The following files to modifiy will be relative to Arduino-->libraries-->IBM_LMIC_framework.
- Navigate and edit
src-->hal-->hal.cpp
- Locate the line SPISettings and set to the following
static const SPISettings settings(10E6, MSBFIRST, SPI_MODE0);
EDIT: We are finding that for the Feather M0 it is best to leave this as10E6
.
- Navigate and edit
src-->lmic-->config.h
- Ensure that the US915 band is selected and the EU868 band is commented out.
//#define CFG_eu868 1
#define CFG_us915 1
- Ensure that the correct radio is selected
// This is the SX1276/SX1277/SX1278/SX1279 radio, which is also used on
// the HopeRF RFM95 boards.
#define CFG_sx1276_radio 1
Before the next section please register an account on The Things Network (https://thethingsnetwork.org).
The example sketch can be found in the folder ttn-featherm0-otaa
. This sketch is different from the default example sketch and contains changes that are required for the US915 band and TTN.
- In the Console select Applications-->Register Application.
- Add an Applications ID. In my case
ttn-getting-started
. - The Description is optional.
- Do not change the Application EUI, the system will generate the ID automatically.
- For the Handler registration choose the region closest to your location. I chose
ttn-handler-us-west
. - Click on Add Application to continue.
- In the Application Overview select Register Device.
- Add a Device ID. This is a human readable name that help identify the device. I chose
featherm0-first-node
. - Add the Device EUI. In many cases the Device EUI comes pre-installed in the node. However, because we are creating our own node from scratch we need to invent one. The Device EUI needs 8 hexadecimal bytes. I went to https://www.random.org/bytes/ and generated a random EUI by selecting
8
bytes andHexadecimal
. - The App Key will be generated by the system.
- The App EUI should already be filled in.
- Click on Register to continue.
- After sucessful registration, maintain the Device Overview page open for the next section.
- In order to copy the Device EUI, Application EUI and App Key to our sketch we need to modify the format and change the order of some bytes.
- In the Device Overview click on the
<>
button for each of the keys. The format should change to "C-style". See image below. - Also ensure that the Device EUI is in
lsb
order by using the arrow button, the Application EUI should be inlsb
order and App Key inmsb
order. See image below. - Now copy the keys one by one into the configuration. Device EUI copies into
DEVEUI
. Application EUI copies intoAPPEUI
. App Key copies intoAPPKEY
. - Modify the
lmic_pinmap
(already done in the example code but good for reference):
// Pin mapping Feather M0
const lmic_pinmap lmic_pins = {
.nss = 8,
.rxtx = LMIC_UNUSED_PIN,
.rst = 4,
.dio = {3, 6, 11},
};
- Use only the US915 sub band channels 8-15 and "relax" the clock (already done in the example code but good for reference):
LMIC_selectSubBand(1);
//Disable FSB1, channels 0-7
for (int i = 0; i < 7; i++) {
if (i != 10)
LMIC_disableChannel(i);
}
//Disable FSB2-8, channels 16-72
for (int i = 16; i < 73; i++) {
if (i != 10)
LMIC_disableChannel(i);
}
LMIC_setClockError(MAX_CLOCK_ERROR * 1 / 100);
- In the Arduino IDE make sure that the board
Feather M0
is selected. - After the sketch uploads open the Serial Monitor and ensure that the speed is set to 9600.
- If everything is correct, the Join process could take several seconds:
- The Device Overview on The Things Network console should now show the Status of the last time the node contacted the gateway:
- Click on the Data tab to see the incoming data. The message "hello world" will be represented in hexadecimal as
68656C6C6F20776F726C64
. - Note that the window in the Console does not have historical data.