This guide was created on behalf of the Arm Software Developers team, follow us on Twitter: @ArmSoftwareDev and YouTube: Arm Software Developers for more resources!
AboutThis project will guide you through connecting your Adafruit Feather RP2040 board to The Thing Networks using LoRaWAN communications.
The focus will be on basic LoRaWAN communications, where the board will periodically send its internal temperature and messages sent to the board will be used to control the built-in LED.
While the guide focuses on the Adafruit Feather RP2040 board, any board equipped with Raspberry Pi's RP2040 microcontroller (MCU), such as the Raspberry Pi Pico, can be used. You will also need a Semtech SX1276 radio module or breakout, such as the Adafruit RFM95W LoRa Radio Transceiver Breakout - 868 or 915 MHz - RadioFruit, if you are not using the Adafruit LoRa Radio FeatherWing - RFM95W 900 MHz - RadioFruit used in this guide.
What is LoRaWAN?LoRaWAN is a networking protocol specification for Low Power Wider Area Networks. It uses Semtech's LoRa (Long Range) wireless radio technology as the physical layer - which allows for long range communications (5 - 20 km with the right antenna's and line of sight) at low data rates (0.3 to 50 kbps).
A LoRaWAN network consists of several components: End Nodes, Gateways / Concentrators, a Network Server, and a Application Server. The Thing Network - LoRaWAN Architecture page has a great explanation of these components.
LoRaWAN Nodes are embedded devices that send and receive data - we'll be focusing on creating a LoRaWAN Node in this guide.
What is The Things Network?The Things Network is a global community building an open-source and decentralized LoRaWAN network.
The network consists of 19k+ community run LoRaWAN Gateways spread over 150+ countries worldwide and is used by 142k+ community members around the world.
For this guide, you'll need to ensure a The Things Network (TTN) Gateway is in range, please check the TTN Map for network coverage. If there are no TTN Gateways in your area you can buy a TTN Indoor Gateway for development and experimenting with TTN and LoRaWAN.
The Adafruit Feather RP2040 board does not come with any headers soldered on it. You'll need to solder the Short Headers Kit for Feather - 12-pin + 16-pin Female Headers to the board with a soldering iron.
Next solder the Male headers onto the Adafruit LoRa Radio FeatherWing - RFM95W 900 MHz - RadioFruit along with the Simple Spring Antenna - 915MHz. See the Radio FeatherWing Assembly Guide for more details.
Out of the box the LoRa Radio FeatherWing only connects the SPI data pins to the header pins. We'll need to also solder the DIO1, IRQ, CS and RST connectors on the Feather Wing to connectors B, C, D and E (Note: these connections are flexible and can be changed in the software).
Plug the FeatherWing on top of the Feather board.
You'll first need to setup you computer with Raspberry Pi's Pico SDK and required toolchains.
See the "Getting started with Raspberry Pi Pico" for more information.
Section 2.1 of the guide can be used for all Operating Systems, followed by the operating specific section:
- Linux: Section 2.2
- macOS: Section 9.1
- Windows: Section 9.2
Make sure the PICO_SDK environment variable is set.
export PICO_SDK_PATH=/path/to/pico-sdk
In a terminal window, clone the git repository and change directories:
cd ~/
git clone --recurse-submodules https://github.com/sandeepmistry/pico-lorawan.git
cd pico-lorawan
Create a build directory and change directories to it:
mkdir build
cd build
Run cmake and make to compile:
cmake .. -DPICO_BOARD=adafruit_feather_rp2040
make
Obtaining the boards default Dev EUIWe'll need a unique identifier for the board when registering the one of the examples included in the library can be used to print it out.
Plug in the board to your computer with a USB cable and then hold done the BOOTSEL button and then tap the RESET button on the board,
Copy the examples/default_dev_eui/pico_lorawan_default_dev_eui.uf2 file to the mounted Raspberry Pi Pico boot ROM disk:
cp examples/default_dev_eui/pico_lorawan_default_dev_eui.uf2 /Volumes/RPI-RP2/.
Use a serial monitor application to such as screen to open view the USB serial output from the board, replacing /dev/cu.usbmodem0000000000001 with the path of your board:
screen /dev/cu.usbmodem0000000000001
The boards defaults Dev EUI which is based on the boards flash serial number will be display, in the screenshot below the value is "4545373038056807".
Make note of this value for the next step.
Adding the Device to The Things NetworkThe Things Network has deprecated their V2 stack which will be turned off at the end of 2021 and recommending users more to the V3 stack now. The V3 is now call "The Things Stack Community Edition". This section will guide you through setting up a Node on the V3 stack.
Go to the The Things Stack Community Edition Console and select your region.
Next click the "Login with The Things ID" button
If you don't already have an account with TTN click Register to create one and then login.
After logging in, click on "Go to applications".
If you don't have an existing Application, click the "Add application" button to create one.
Enter an Application ID, we used "feather-rp2040-app" below, and then the click "Create application" button.
Click the "Add end device" button to create a new device.
Click the "Manually" tab, as the device we are creating is not in The LoRaWAN Device Repository.
Select "Over the air activation (OTAA)" as the Activation mode, and "MAC V1.0.2" as the LoRaWAN Version. The rest of the field can be left with their default values and you can then click the "Start" button.
Next enter an "End device ID", in the screenshot below "feather-rp2040" was entered, enter all 0's for the JoinEUI, and use default Dev EUI value you obtained from your board for the DevEUI field. Then click the "Network layer settings" button.
Select the "Frequency plan" for your region and the "Regional Parameters version" as PHY V1.0.2 REV A, Then click the "Join settings" button.
Click the circular arrow buttons next to the AppKey to generate an AppKey, then click the "Add end device" button.
Now that the device has been added make note of the JoinEUI, DevEUI and AppKey values for later on.
Configure the boards OTAA settingsOpen the examples/otaa_temperature_led/config.h and enter the information from the obtained from the previous section.
Example for US915:
#define LORAWAN_REGION LORAMAC_REGION_US915
// set to NULL use the boards default Dev EUI
#define LORAWAN_DEVICE_EUI NULL
// Join EUI
#define LORAWAN_APP_EUI "0000000000000000"
#define LORAWAN_APP_KEY "00DBE0B97B52F2F01A406CC8B3830753"
// TTN specific channel mask, only needed for US915 region
#define LORAWAN_CHANNEL_MASK "FF0000000000000000020000"
Example for EU868:
#define LORAWAN_REGION LORAMAC_REGION_EU868
// set to NULL use the boards default Dev EUI
#define LORAWAN_DEVICE_EUI NULL
// Join EUI
#define LORAWAN_APP_EUI "0000000000000000"
#define LORAWAN_APP_KEY "00DBE0B97B52F2F01A406CC8B3830753"
// set to NULL for default channel mask
#define LORAWAN_CHANNEL_MASK NULL
Now re-compile the examples with the updated OTAA settings:
make
Hold down the BOOTSEL button and then tap the RESET button on the board,
Copy the examples/otaa_temperature_led/pico_lorawan_otaa_temperature_led.uf2 file to the mounted Raspberry Pi Pico boot ROM disk:
cp examples/otaa_temperature_led/pico_lorawan_otaa_temperature_led.uf2 /Volumes/RPI-RP2/.
Use a serial monitor application to such as screen to open view the USB serial output from the board, replacing /dev/cu.usbmodem0000000000001 with the path of your board:
screen /dev/cu.usbmodem0000000000001
If successful the board will join TTN and start sending the internal temperature sensors value every 30 seconds.
You can also see the boards status in the TTN console.
Click "Live data" to see live data from the board:
The data message values are in hexadecimal and should match the ones that appear on the serial monitor. In the screenshot above 0x26 = 38 Β°C.
Next we can send a downlink message to the board, click the "Messaging" tab.
Then "Downlink", and enter 01 as the Payload and then click the "Simulate uplink" button. Note: if the button is disabled, you can refresh the page to enable it.
Once the board received the downlink message it's onboard LED will light up and a message will also be display on the serial monitor:
LoRaWAN Class B devices can only receive downlink messages in a specific window period after they send an uplink message. The example we loaded sends a message every 30 seconds so you will have to wait up to a minute to receive it.
You can now send another downlink message with 00 to the board to clear the LED.
We've covered how to create an RP2040 based LoRaWAN Node using the Raspberry Pi Pico SDK and the pico-lorawan library with The Things Network V3. The example application we created sends the boards internal temperature up to TTN every 30 seconds and downlink messages can control the board's LED remotely.
You can now build upon this example by:
- Adding more sensor values in uplink messages
- Use additional values from downlink messages to control other actuators
- Follow on of The Things Stacks Integration guides to handle downlink messages on an application with HTTP web hooks, MQTT, NODE-Red, IFFT or Cloud Platforms, such as AWS IoT.
Since the Raspberry Pi RP2040 includes dual core functionality, you can also create more advance projects that could collect and use Machine Learning on one core while letting the other core handle LoRaWAN communications to TTN.
If you used this guide to make a cool project please create a project guide for it on Hackster.io for others to enjoy!
Hear more from The Things Network team and see this project in action during this weekβs Arm Innovation Coffee on April 29th @ 5pm UTC.
Comments