Tutorial: RAK813 LoRaWAN+BLE+GPS Sensor Node with Eclipse IDE

In the IoT world, it is all about security, connectivity and low power. LoRaWAN with the Things Network is able to connect devices over…

erich-styger
about 5 years ago

In the IoT world, it is all about security, connectivity and low power. LoRaWAN with the Things Network is able to connect devices over several kilometers, and I’m running my gateway for it already (see “Contributing an IoT LoRaWAN Raspberry Pi RAK831 Gateway to The Things Network“). This tutorial is about building a BLE+LoRaWAN+GPS sensor node with GNU tools and Eclipse.

LoRa+BLE with RAK813 and LPC845

As for hardware, I’m using the RAK815 board which features the RAK813 BLE+LoRaWAN module from RAK Wireless.

I ordered the RAK815 board from AliExpress as a kit (EU868) for $52 which includes everything to get started:

RAK815 Kit

The board packs a RAK813 module (nRF52832+SX1276), a u-blox GPS module, and an SHT31 humidity/temperature sensor, plus the LIS3DH accelerometer.

Setup

For this tutorial, you need:

  • RAK815 board with RAK813 module (search on AliExpress: “RAK815”)

To set up the IDE+toolchain, see this tutorial how to setup a DIY IDE.

The picture below shows my setup. The RAK815 includes a nRF52832 (Arm Cortex-M4F with 512KB Flash and 64KB RAM). I’m using it in combination with the NXP LPC845-BRK board.

Hardware setup

Because the original projects provided by RAK Wireless are for IAR and Keil only, I have ported them to Eclipse — that way a free-of-charge IDE and compiler can be used.

The complete project is available on GitHub (see the links at the end of this article).

Below are the porting steps:

Creating Project

First, clone the repository from https://github.com/RAKWireless/RAK813-BreakBoard.

Then create an empty project for GNU Arm Embedded.

Add the Apps, Board, LoRa_Lib and nRF_Lib folders as linked folders to the project. Add startup code and system files:

Linked folders

Files not used have to be ‘excluded from build,’ see “Exclude Source Files from Build in Eclipse.”

In the project settings, use the Arm Cortex-M4 with FPU:

Arm compiler settings

Add the following folders to the compiler include settings:

Compiler includes
../../nRF_Lib/components/toolchain/cmsis/include
../../Apps
../../Board
../../Board/lora_board
../../Board/peripherals
../../LoRa_Lib/mac
../../LoRa_Lib/mac/region
../../LoRa_Lib/radio
../../LoRa_Lib/radio/sx1276
../../LoRa_Lib/system
../../LoRa_Lib/system/crypto
../../nRF_Lib/external/fprintf
../../nRF_Lib/external/segger_rtt
../../nRF_Lib/components/boards
../../nRF_Lib/components/device
../../nRF_Lib/components/ble/ble_services/ble_nus
../../nRF_Lib/components/toolchain
../../nRF_Lib/components/softdevice/common
../../nRF_Lib/components/softdevice/s132/headers
../../nRF_Lib/components/softdevice/s132/headers/nrf52
../../nRF_Lib/components/drivers_nrf/clock
../../nRF_Lib/components/drivers_nrf/common
../../nRF_Lib/components/drivers_nrf/gpiote
../../nRF_Lib/components/drivers_nrf/rtc
../../nRF_Lib/components/drivers_nrf/spi_master
../../nRF_Lib/components/drivers_nrf/timer
../../nRF_Lib/components/drivers_nrf/uart
../../nRF_Lib/components/drivers_nrf/twi_master
../../nRF_Lib/components/libraries/balloc
../../nRF_Lib/components/libraries/bsp
../../nRF_Lib/components/libraries/util
../../nRF_Lib/components/libraries/button
../../nRF_Lib/components/libraries/experimental_log
../../nRF_Lib/components/libraries/experimental_memobj
../../nRF_Lib/components/libraries/fds
../../nRF_Lib/components/libraries/fifo
../../nRF_Lib/components/libraries/fstorage
../../nRF_Lib/components/libraries/uart
../../nRF_Lib/components/libraries/experimental_section_vars
../../nRF_Lib/components/drivers_nrf/hal
../../nRF_Lib/components/libraries/strerror
../../nRF_Lib/components/libraries/experimental_log/src
../../nRF_Lib/components/libraries/timer
../../nRF_Lib/components/drivers_nrf/delay
../../nRF_Lib/components/libraries/atomic
../../nRF_Lib/components/libraries/pwr_mgmt
../../nRF_Lib/components/ble/common
../../nRF_Lib/components/libraries/mutex
../../nRF_Lib/components/ble/ble_advertising
../../nRF_Lib/components/drivers_nrf/wdt
../../nRF_Lib/components/ble/nrf_ble_gatt
../../nRF_Lib/components/libraries/mem_manager
../../nRF_Lib/components/ble/ble_db_discovery
../../nRF_Lib/components/ble/peer_manager
../../nRF_Lib/components/libraries/atomic_fifo

Define the following in the compiler preprocessor defined symbols:

Preprocessor settings
BOARD_CUSTOM
USE_APP_CONFIG
NRF52
NRF52832_XXAA
NRF52_PAN_74
NRF_SD_BLE_API_VERSION=5
S132
SOFTDEVICE_PRESENT
SWI_DISABLE0
CONFIG_GPIO_AS_PINRESET
REGION_EU868

Specify the linker file:

Linker file

Link the Math library and use ‘..’ as library path to find the linker file:

Math library

Use the newlib-nano without syscalls:

Library options

The linker file needs to match the size of the SoftDevice. Using the S123, the start address for the application is 0x23000:

MEMORY
{
  FLASH (rx) : ORIGIN = 0x1c000+0x7000, LENGTH = 0x64000-0x7000 
  RAM (rwx) :  ORIGIN = 0x20002a68, LENGTH = 0xd598
}

With this, the application should build just fine

Application build with Eclipse
Debug Connection

The board does not have a standard debug header :-(, so I have to build an adapter:

SWD debug header (📷: RAK815 Schematics)

I’m using the J-Link Mini which has the 10pin mini SWD/JTAG connector. With the Adafruit Debug adapter I can connect the wires:

Debug connection
SoftDevice

As a first step, the SoftDevice needs to be programmed. Use the nRFgo Studio and use the following SoftDevice file:

/nRF_Lib/components/softdevice/s132/hex/s132_nrf52_5.0.0_softdevice.hex
Debug configuration

Notice that the SoftDevice will use the Region 1 up to 0x23000: this is how we have configured the linker file.

Debug

Now we can use GDB to download and debug the target. Create a new .launch Debug configuration. Check that it is pointing to the correct Segger Client and GDB server:

Debugging LoRaWAN application

With this, I’m debugging the application:

It reports the status to the serial console:

Console output
Note: the EUI’s and keys are defined in Commissioning.h or can be configured with the smartphone using the BLE connection.
Summary

It took me a while to build that LoRaWAN+BLE demo application, but now I have the power of Eclipse to develop it further. The RAK815 board comes with everything I need to start a first prototypes for a larger application. With the BLE I can connect to a smartphone (using a virtual UART), and with the LoRaWAN I can communicate to the gateways in my area. The board includes a SSD1306 I2C LCD interface which I plan to add in a next step.

Happy RAKing :-)

Links

Originally published at mcuoneclipse.com on March 23, 2019

Latest Articles