Use Lora Shield + Arduino set up a Lora Node

From Wiki for Dragino Project
Jump to: navigation, search

Use LoRa Shield + Arduino set up a LoRa Node

Use LoRa Shield + Arduino set up a LoRa Node


LoRa Technology is a wireless modulation for long-range, low-power, low-data-rate applications. By achieving a range of more than 
15 kilometers in a suburban environment and more than 2 kilometers in a dense urban environment, LoRa technology solutions target 
multiple application domains, such as Internet-of-Things (IoT), metering, security, and machine-to-machine (M2M).

This single channel LoRaWAN gateway is a proof-of-concept implementation,that can be used for development and node testing. It is 
not a replacement for a real multi channel/multi SF gateway! It supports some LoRaWAN features, but due to its static nature(single channel) 
it is not fully LoRaWAN compatible (and will never be). 

By default it works with the TTN backend, for testing and development.
                                                                                            -------------Refer to the summary of Thomas


Over here,we will use the LoRa Shileld + MEGA2560 and LoRa/GPS HAT + Raspberry Pi to build a single channel LoRaWAN gateway.

This demo include:

  • How to use LoRa/GPS HAT to set up single channel gateway for TTN network.
  • How to use LoRa Shield to set up a LoRa Node.
  • How is the communication between the LoRa Node and LoRa Gateway.


In this project,we use the things as followed list:

  • LoRa/GPS HAT X 1
  • LoRa Shields X 1
  • Raspberry Pi 2/3 model B(Installed Raspbian) X 1
  • ARDUINO MEGA 2560 X 1
  • LED display screen X 1
  • USB cables X 2
  • Antennas(868MHZ) X 2
  • PC X 1
  • Wireless network card X 1
  • Mouse and keyboard x 1
  • Some wires

Network structure

Network structure of arduino node

The construction of this network is as the photo above.

LoRa Node:

The Mega2560 will get sensor data and control the LoRa Shield to send this data to the RPi Lora Gateway via LoRa wireless protocol.

LoRa Gateway:

The RPi LoRa Gateway will receive this data and upload it to the TTN network via the Internet.

TTN Server:

The TTN Server will get the data packets from the RPi LoRa Gateway and the data will be stored in the corresponding place,so users can take what they need from the Internet.


We can use the PC to get the data and check the status of this LoRa Gateway network.

Create a Gateway on TTN network


Before we start this project we must have a TTN account,we can create one at this page:

Create ttn gateway

NOTE: Create your own loRa gateway is not necessary, if there are TTN lora gateway around, you don't have to create your own one. in this instruction, we want to demo the full network structure so we create gateway here.

Gateway EUI

Login the TTN network by your own account and configure 'My Profile' on the web.

TTN Gateway

Click 'add a gateway' and you will enter a page to type your gateway message.In the next step,we will get a Gateway ID after we run the packet forward on the RPi.Then type the Gateway ID to the Gateawy EUI column(In hexadecimal, no colons,uppercase letters).

We can see the ruuning result as the 3rd picture in this step,we get a Gateway ID: b8:27:eb:ff:ff:29:4b:3b,so we type B827EBFFFF294B3B to the Gateway EUI column.

Single Channel LoRa Gateway

By the way,we also need to modify other settings(Select the Status active,type a title for this Gateway,delect Automatically update status and coordinates...),save it and you will see your profile such as above picture.It means we just have created a Gateway for our TTN account.

Build a single channel LoRaWAN gateway

Gateway Status

In this step,we will use the RPi and the LoRa/GPS HAT to build a single channel LoRaWAN Gateway.We should configure the RPi and connect it with the LoRa/GPS HAT.Complete the operations as following description:


  • Connect the Raspberry Pi to the Internet;
  • Use 'raspi-config ' to ensure that SPI can be used on RPi ;
  • Use 'sudo apt-get install wiringpi' to install the GPIO access library written in C for the BCM2835 used in the Raspberry Pi;
  • Get the single channel Lora Gateway source code from here ;
  • Edit the 'main.cpp' to change configuration (look for: "Configure these values!").


  • LoRa: SF7 at 868.1 Mhz
  • Server:, port 1700 (The Things Network:

So,we don't need too change the code here.

Dragino LoRa/GPS_HAT

Connect the Dragino LoRa/GPS HAT and the RPi as above,run packet forwarder as root. Then we can get a Gateway ID and see the running result on the RPi as below picture.

Get a Gateway ID

We also can get the Gateway status from as the last photo at this step. In this URL you should change 'B827EBFFFF294B3B' to your own Gateway ID. If you can see the Gateway status on the web,it shows the LoRaWAN Gateway is working!

Note: If the packet forwarder shows the "unrecognized transceiver" message,this mean the RPi can't detect LoRa/GPS HAT, in this case please further check your pin/wiring configuration.

Connect the LoRa Shield and MEGA 2560,upload the sktech

Arduino LoRa Node Connection

Connect the LoRa Shield and MEGA 2560,and put the 868MHZ antenna on it.Connect them to the computer via an USB cable.

Over here,we use the Arduino IDE1.68,we need to install this Arduino-LMIC liabrary.This repository contains the IBM LMIC (LoraMAC-in-C) library, slightly modified to run in the Arduino environment, allowing using the SX1272, SX1276 tranceivers and compatible modules.

Note:This library requires Arduino IDE version 1.6.6 or above, since it requires C99 mode to be enabled by default.

After do that,we download the ttn sketch from this link.

Sketchc of LoRa Node

Open and modify this sktech,change the 'DEVADDR' as your node_eui on line 40th,choose the right port and right board to upload the sktech.We can see the running result on the Serial Monitor if everything is ok.(4th photo)

LoRa Node running result

At the same time we can also see the corresponding results on RPi.By default,the node is sending at 10 frequencies, the gateway is receiving at only 1, hence the one packet per 10 minutes.

receive pkt fwd
On a "real" gateway I see all messages (each minute), only with this Single Channel Gateway was this phenomena.
This is not a real gateway, it is for testing purposes. It is LoRaWAN compatible, but not compliant.

Refer to [1] and [2]

If you are using LoRa Shield v1.1 version. please wired as below code:

LoRa Shield v1.1 Wiring
// Pin mapping<br>const lmic_pinmap lmic_pins = {
    .nss = 10,// Connected to pin D10
    .rxtx = LMIC_UNUSED_PIN,// For placeholder only, Do not connected on RFM92/RFM95
    .rst = 9,// Needed on RFM92/RFM95? (probably not)
    .dio = {2, 6, 7},// Specify pin numbers for DIO0, 1, 2
// connected to D2, D6, D7 


Running Result on TTN

Above all completed,open the URL with your node_eui and you will see the running result on the ttn network.For example,our 'DEVADDR'/node_eui is '09984507',so we can check it on

By the way,we can get this LoRa Shield from


How to use 915MHZ Dragino LoRa boards in this project

You can get info from: Use the LMIC with 915MHZ Dragino Lora boards