# LoRa and LoRaWAN Radio for Raspberry Pi

## Overview

If you're building a Raspberry Pi project and need to send data back-and-forth, the WiFi module built into newer Pi's should be fine for most cases.

_However_, WiFi does not have a long range and also requires both investment (through your ISP) and setup (routers, access points, network security schemes).

If you're deploying your project somewhere more remotely, without WiFi or a strong cellular network, like a farm, you'll need another option. Something that can be deployed quickly with no overhead setup and that will transmit/receive over a long distance.

![](https://cdn-learn.adafruit.com/assets/assets/000/068/451/medium800/pi_a___b___2__3_800px-Wayne_county_ky_farmland.jpg?1546270264 The original uploader was Rwmcfa1 at English Wikipedia., Wayne county ky farmland, CC BY-SA 3.0)

By sacrificing transmit speed and the amount of data which you're able to send, packet radios can transmit much farther than Bluetooth Low-Energy and WiFi.

This makes using a **&nbsp;radio** perfect for scenarios where your project would need to periodically transmit sensor and/or device data (such as the Pi's battery life) over a long distance. The RFM69 module can transmit up to 50m and the RFM9x module can send packets up to 2km over LoRa and even further using LoRaWAN!

## Parts
### Raspberry Pi 3 - Model B+ - 1.4GHz Cortex-A53 with 1GB RAM

[Raspberry Pi 3 - Model B+ - 1.4GHz Cortex-A53 with 1GB RAM](https://www.adafruit.com/product/3775)
The Raspberry Pi 3 Model B is the most popular Raspberry Pi computer made, and the Pi Foundation knows you can always make a good thing _better_! And what could make the Pi 3 better? How about a&nbsp;_faster_ processor, 5 GHz WiFi, and updated Ethernet chip with PoE capability?...

In Stock
[Buy Now](https://www.adafruit.com/product/3775)
[Related Guides to the Product](https://learn.adafruit.com/products/3775/guides)
![Angled shot of Raspberry Pi 3 - Model B+](https://cdn-shop.adafruit.com/640x480/3775-11.jpg)

### Raspberry Pi Zero - Version 1.3

[Raspberry Pi Zero - Version 1.3](https://www.adafruit.com/product/2885)
At first glance, the Pi Zero isn't much. &nbsp;It just looks like a slimmed down version of the Raspberry Pi we know and love. &nbsp;But when we started to think of the possibilities - [and what a well-chosen set of accessories could add](https://www.adafruit.com/product/2816) -...

In Stock
[Buy Now](https://www.adafruit.com/product/2885)
[Related Guides to the Product](https://learn.adafruit.com/products/2885/guides)
![Angled shot of Raspberry Pi Zero computer](https://cdn-shop.adafruit.com/640x480/2885-06.jpg)

## All-in-One

The **Adafruit LoRa Radio Bonnet&nbsp;for Raspberry Pi&nbsp;** sets you up with a RFM95W Radio Module, a 128x32 OLED display and three push-buttons for LoRa and LoRaWAN experiments.

### Adafruit LoRa Radio Bonnet with OLED - RFM95W @ 915MHz

[Adafruit LoRa Radio Bonnet with OLED - RFM95W @ 915MHz](https://www.adafruit.com/product/4074)
The latest Raspberry Pi computers come with WiFi and Bluetooth®, and now you can add even more radio options with the Adafruit Radio Bonnets! Upgrade your Raspberry Pi with a LoRa/LoRaWAN radio so it can communicate over very long distances. These bonnets plug right into your Pi and give...

In Stock
[Buy Now](https://www.adafruit.com/product/4074)
[Related Guides to the Product](https://learn.adafruit.com/products/4074/guides)
![A rectangular microcontroller with OLED screen. A blue-manicured index finger presses buttons below the OLED screen, triggering different texts.](https://cdn-shop.adafruit.com/product-videos/640x480/4074-03.jpg)

There's also a 433MHz version which uses the amateur or license-free ISM band (ITU "Europe" license-free ISM or ITU "American" amateur with limitations).

## Breadboard Parts
You'll need a way to access the GPIO (pins) from the Raspberry Pi. The T-Cobbler plus is a plug-and-play breakout which works with almost every new Raspberry Pi variation.&nbsp;

### Assembled Pi T-Cobbler Plus - GPIO Breakout

[Assembled Pi T-Cobbler Plus - GPIO Breakout](https://www.adafruit.com/product/2028)
 **This is the assembled version of the Pi T-Cobbler Plus. &nbsp;It only works with the Raspberry Pi Model Zero, A+, B+, Pi 2, Pi 3 & Pi 4!** (Any Pi with 2x20 connector)  
  
The Raspberry Pi has landed on the Maker World like a 40-GPIO pinned, quad-USB ported, credit...

In Stock
[Buy Now](https://www.adafruit.com/product/2028)
[Related Guides to the Product](https://learn.adafruit.com/products/2028/guides)
![Angled shot of Assembled Pi T-Cobbler Plus next to GPIO ribbon cable](https://cdn-shop.adafruit.com/640x480/2028-07.jpg)

The Pi setup used for this guide is operated as a headless Pi. This means that no monitor is plugged into the Pi and we control it over SSH. We'll add a small display to monitor and interact with the code.

## Sending Data using LoRa
The RFM9x LoRa comes in two different frequencies - 868/915MHz and 433MHz. It can broadcast over LoRa (longer range than the RFM69HCW) and LoRaWAN (even longer range to gateways).&nbsp;

### Adafruit RFM95W LoRa Radio Transceiver Breakout - 868 or 915 MHz

[Adafruit RFM95W LoRa Radio Transceiver Breakout - 868 or 915 MHz](https://www.adafruit.com/product/3072)
_"You see, wire telegraph is a kind of a very, very long cat.&nbsp; You pull his tail in New York and his head is meowing in Los Angeles.&nbsp; Do you understand this? And radio operates exactly the same way: you send signals here, they receive them there.&nbsp; The only difference is..._

In Stock
[Buy Now](https://www.adafruit.com/product/3072)
[Related Guides to the Product](https://learn.adafruit.com/products/3072/guides)
![Angled shot of a Adafruit RFM95W LoRa Radio Transceiver Breakout.](https://cdn-shop.adafruit.com/640x480/3072-07.jpg)

There's also a 433MHz version which uses the amateur or license-free ISM band (ITU "Europe" license-free ISM or ITU "American" amateur with limitations).

### Part: LoRa Breakout RFM96W
quantity: 1
LoRa Radio Module - 433MHz Version
[LoRa Breakout RFM96W](https://www.adafruit.com/product/3073)

## Materials
If you don't have these parts already, grab them from the Adafruit store:

### Part: Tactile Switch Buttons
quantity: 1
10-pack of medium-sized momentary switches
[Tactile Switch Buttons](https://www.adafruit.com/product/1119)

### Part: Power Supply w/MicroUSB
quantity: 1
5V 2.5A Switching Power Supply
[Power Supply w/MicroUSB](https://www.adafruit.com/product/1995)

### Part: 8GB MicroSD
quantity: 1
8GB MicroSD with NooBs 2.9
[8GB MicroSD](https://www.adafruit.com/product/3259)

### Part: Full sized breadboard
quantity: 1
This is a 'full-size' breadboard, 830 tie points. Good for small and medium projects.
[Full sized breadboard](https://www.adafruit.com/product/239)

### Part: Breadboarding wire bundle
quantity: 1
75 flexible stranded core wires with stiff ends molded
[Breadboarding wire bundle](https://www.adafruit.com/product/153)

# LoRa and LoRaWAN Radio for Raspberry Pi

## Raspberry Pi Wiring

# Raspberry Pi Radio Bonnet Wiring
### Adafruit LoRa Radio Bonnet with OLED - RFM95W @ 915MHz

[Adafruit LoRa Radio Bonnet with OLED - RFM95W @ 915MHz](https://www.adafruit.com/product/4074)
The latest Raspberry Pi computers come with WiFi and Bluetooth®, and now you can add even more radio options with the Adafruit Radio Bonnets! Upgrade your Raspberry Pi with a LoRa/LoRaWAN radio so it can communicate over very long distances. These bonnets plug right into your Pi and give...

In Stock
[Buy Now](https://www.adafruit.com/product/4074)
[Related Guides to the Product](https://learn.adafruit.com/products/4074/guides)
![A rectangular microcontroller with OLED screen. A blue-manicured index finger presses buttons below the OLED screen, triggering different texts.](https://cdn-shop.adafruit.com/product-videos/640x480/4074-03.jpg)

The&nbsp; **Radio Bonnet for Raspberry Pi&nbsp;** sets you up with a RFM9x (or RFM69HCW) Radio Module, a 128x32 OLED display and three push-buttons.&nbsp;

If you have this bonnet, everything is already "wired up" for you - move on to setting up your Raspberry Pi.

# Raspberry Pi Breadboard Wiring
## Wiring the Push-Buttons
We'll start by wiring three buttons. These will the physical interface between the Raspberry Pi and the Radio - we'll want to control the radio by pressing some buttons.

![](https://cdn-learn.adafruit.com/assets/assets/000/068/454/medium800/pi_a___b___2__3_rfm_btns_only.png?1546273133)

Make the following connections between the Pi and the three push-buttons:

- **Pi GPIO #5** &nbsp;to **Button A&nbsp;** (orange wire)
- **Pi GPIO #6** &nbsp;to **Button B&nbsp;** (blue wire)
- **Pi GPIO #12** &nbsp;to **Button C&nbsp;&nbsp;** (green wire)
- **Pi 3.3V&nbsp;** to&nbsp; **Power Rail&nbsp;** (red wire)
- **Pi GND&nbsp;** to&nbsp; **Ground Rail&nbsp;** (black wire)

## Wiring the OLED
![](https://cdn-learn.adafruit.com/assets/assets/000/084/509/medium800/raspberry_pi_rfm9x_bb_oled_only.png?1574086428)

- **Pi 3.3V&nbsp;** to **&nbsp;OLED VIN**
- **Pi GND&nbsp;** to **&nbsp;OLED GND**
- **Pi SCL&nbsp;** to **&nbsp;OLED SCL**
- **Pi SDA&nbsp;** to **&nbsp;OLED SDA**
- **Pi GPIO4&nbsp;** to **&nbsp;OLED RST**

## Wiring the RFM Radio Module
![](https://cdn-learn.adafruit.com/assets/assets/000/091/522/medium800/raspberry_pi_rfm9x_bb_2.png?1590505703)

Make the following connections between the **Raspberry**  **Pi** and the **RFM Radio Module** :

- **Vin&nbsp;** to&nbsp; **Raspberry Pi 3.3V**
- **GND&nbsp;** to **Raspberry Pi Ground**
- **RFM G0&nbsp;** to&nbsp; **Raspberry Pi GPIO #5**
- **RFM RST&nbsp;** to&nbsp; **Raspberry Pi GPIO #25**
- **RFM SCK** to&nbsp; **Raspberry Pi SCK**
- **RFM MISO&nbsp;** to&nbsp; **Raspberry Pi MISO**
- **RFM MOSI&nbsp;** to&nbsp; **Raspberry Pi MOSI**
- **RFM CS&nbsp;** to&nbsp; **Raspberry Pi CE1**

Next, let's move on to installing the necessary files for this project.

# LoRa and LoRaWAN Radio for Raspberry Pi

## LoRa Raspberry Pi Setup

This guide assumes that you've gotten your Raspberry Pi up and running, have CircuitPython installed, and are using a virtual environment.&nbsp;

If you have not done this, please follow the steps in this guide below,

- [https://learn.adafruit.com/circuitpython-on-raspberrypi-linux/installing-circuitpython-on-raspberry-pi](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux/installing-circuitpython-on-raspberry-pi)

## Installing CircuitPython Libraries

We're running CircuitPython on the Raspberry Pi, installing the libraries for radio communication is simple.

If you on Raspberry Pi OS Bookworm or newer, please start by configuring a virtual environment (VENV). If you do not know how to do this, follow this link:&nbsp;[https://learn.adafruit.com/python-virtual-environment-usage-on-raspberry-pi/basic-venv-usage](https://learn.adafruit.com/python-virtual-environment-usage-on-raspberry-pi/basic-venv-usage)

Once the virtualenv is set up, to&nbsp; **install the library for the display** , **enter the following into the terminal:**

**`sudo pip3 install adafruit-circuitpython-ssd1306`**

You'll also need to **install the framebuf module** in order to write to the display.&nbsp;

`sudo pip3 install adafruit-circuitpython-framebuf`

To install the library for the **RFM9x** Module, **enter the following into the terminal:**

**`sudo pip3 install adafruit-circuitpython-rfm9x`**

You'll also want to download the font file, **`font5x8.bin`,** and copy it into the same directory as the script

` wget https://github.com/adafruit/Adafruit_CircuitPython_framebuf/raw/main/examples/font5x8.bin`

[Click to download font5x8.bin](https://github.com/adafruit/Adafruit_CircuitPython_framebuf/blob/master/examples/font5x8.bin)
Make sure the font file is 1282 bytes long, if not something went wrong with the download

![](https://cdn-learn.adafruit.com/assets/assets/000/096/258/medium800/raspberry_pi_image.png?1603405641)

### RFM9x Connection Test!
Warning: 

The following code is for checking if the RFM9x radio is set up for transmitting and receiving. **Save the code on your Pi** (save this to a location you can remember, like your Desktop or Downloads folder)&nbsp;as **`rfm9x_check.py`**.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/pi_radio/rfm9x_check.py

To use the code, copy and paste the following command into your terminal:

`python3 rfm9x_check.py`

Now to check the setup:

If the RFM9x/RFM69 is **detected** , the OLED will display **Detected**. You can test&nbsp; the buttons by pressing them.

![raspberry_pi_bonnet_test.gif](https://cdn-learn.adafruit.com/assets/assets/000/069/466/medium640thumb/raspberry_pi_bonnet_test.jpg?1547664932)

 **If the wiring of the radio module is incorrect** &nbsp;-&nbsp;the display will show&nbsp; **ERROR**. Check over your wiring on the Wiring Page and re-run the test. You may also need to ensure the correct CircuitPython library is installed for the module.&nbsp;

&nbsp;

**If the OLED does not turn on** &nbsp;-&nbsp;first check that it is wired correctly. Then, make sure you enabled I2C from&nbsp;`raspi-config`&nbsp;and installed the required libraries (`adafruit-circuitpython-framebuf`_and_&nbsp;`adafruit-circuitpython-ssd1306`).

![pi_a___b___2__3_IMG_0773.jpg](https://cdn-learn.adafruit.com/assets/assets/000/068/581/medium640/pi_a___b___2__3_IMG_0773.jpg?1546449242)

With everything working, let's move on to using the radio.

Warning: If you are using a Pi 5 and receive a "lgpio.error: 'GPIO busy" error try the following.

## Pi 5 GPIO busy&nbsp;

disable one-wire:

&nbsp;

```terminal
sudo raspi-config nonint do_onewire 1
```

disable CE0 / CE1:

```terminal
curl -fsSL https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/main/raspi-spi-reassign.py -o raspi-spi-reassign.py
sudo -E env PATH=$PATH python3 raspi-spi-reassign.py --ce0=disabled --ce1=disabled
```

# LoRa and LoRaWAN Radio for Raspberry Pi

## Sending Data with LoRa

Warning: 

![](https://cdn-learn.adafruit.com/assets/assets/000/068/479/medium800/pi_a___b___2__3_Lora_logo.png?1546282915 LoRa Logo via lora-alliance.org)

The RFM9x is a more expensive module than the RFM69, but it has a trick - _LoRa_. LoRa is a spread spectrum modulation technique patented by [Semtech](https://www.semtech.com/). It allows your packets to be sent over farther distances (a few km in a city like New York and around 40km in a rural area).

It's also a low power protocol with batteries lasting in the year range, instead of a few days with WiFi. This is made possible by only powering up the LoRa radio when packets are being sent, instead of keeping the radio always-on (like the WiFi radio on your cell phone).

When building a project which uses LoRa, keep in mind that only a few hundred bytes per-transmission can be sent, and that each transmission will cause the battery life to decrease.

If a LoRa project involves a lot of sensors, expect to cram a lot of data into a small packet which is transmitted infrequently.

## RFM9x and CircuitPython

It's easy to use the RFM9x LoRa radio with CircuitPython and the&nbsp;[Adafruit CircuitPython RFM9x](https://github.com/adafruit/Adafruit_CircuitPython_RFM9x)&nbsp;module.&nbsp; This module allows you to easily write Python code that sends and receives packets of data with the radio. &nbsp;

Be careful to note **this library is for the RFM9x&nbsp;(RFM95/96/97/98) Radio**&nbsp;_ **only** _ and&nbsp; **will not** &nbsp; **work** with the RFM69.

To demonstrate how the RFM9x LoRa module sends packets, we'll build an example where we send and receive data between two radios.

## CircuitPython Transmitter/Receiver Example
Below is an example of using the RFM9x to transmit, or receive from, another RFM9x radio. Save this as&nbsp; **radio\_rfm9x.py** &nbsp;on your Raspberry Pi.&nbsp;

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/pi_radio/radio_rfm9x.py

You'll also want to download the font file, **`font5x8.bin`,** and copy it&nbsp;into the same directory as the script:

[font5x8.bin](https://github.com/adafruit/Adafruit_CircuitPython_framebuf/blob/master/examples/font5x8.bin)
To run the example, **enter the following into the terminal** :

**`python3 radio_rfm9x.py`**

Both of the radios will listen for a new incoming packet. When they receive a new packet, they'll print the text from the packet to the display (and to the terminal).

Press any of the three buttons to send data between radios. Pressing button a will send a packet with data 'Button A!' to the other radio, and so on!

![](https://cdn-learn.adafruit.com/assets/assets/000/069/604/medium800thumb/raspberry_pi_rx_tx_oo.jpg?1547825778)

# LoRa and LoRaWAN Radio for Raspberry Pi

## Sending Data over LoRaWAN

Danger: 

## Overview
LoRaWAN is a Low Power Wide Area Network (LPWAN) specification which allows connection of LoRa devices to the internet. LoRaWAN differs from LoRa by the inclusion of a physical layer.

This may seem confusing, but it's really no different from other types of networks (like cellular), except you can use a gateway (like a cell tower) that you own, or someone else owns and operates, to connect your device to the Internet.&nbsp;

One gateway can cover a large area, depending on the obstructions (a gateway operated in NYC would have a range of a few hundred kilometers vs thousands of kilometers in the countryside)

![](https://cdn-learn.adafruit.com/assets/assets/000/068/481/medium800/pi_a___b___2__3_what-is-lorawan_pdf.png?1546283995 Range of LoRaWAN Gateways in Belgium (via https://lora-alliance.org))

We're going to be connecting our Raspberry Pi to [The Things Network](https://thethingsnetwork.org), a LoRaWAN network made up of volunteers operating their own gateways, using CircuitPython.&nbsp;

_Want to learn more about The Things Network and CircuitPython?_ There's a full guide written on the [Adafruit Learning System which dives into deeper detail.](https://learn.adafruit.com/using-lorawan-and-the-things-network-with-circuitpython)

# LoRa and LoRaWAN Radio for Raspberry Pi

## TinyLoRa TTN Setup

Danger: 

Warning: 

Before your Feather can communicate with The Things Network, you'll need to create an application.

First, we're going to register an account with TTN. [Navigate to their account registration page](https://account.thethingsnetwork.org/register) to set up an account.

Once logged in,&nbsp;[navigate to the The Things Network Console](https://console.thethingsnetwork.org/). This page is where you can register applications and add new devices or gateways. Click&nbsp; **Applications** &nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/065/275/medium800/feather_console-application.png?1541611433)

Click **Add Application**.&nbsp;

Fill out an&nbsp; **Application ID** &nbsp;to identify the application, and a **description** of what the application is. We set our&nbsp; **Handler Registration&nbsp;** to match our region, _us-west_. If you're not located in the U.S., TTN provides multiple regions for handler registration.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/065/269/medium800/feather_The_Things_Network_Console.png?1541609514)

Once created, you'll be directed to the Application Overview. From here, you can add devices, view data coming into (and out of) the application, add integrations for external services, and more. We'll come back to this section later in the guide.

**Click&nbsp;Register Device**

![](https://cdn-learn.adafruit.com/assets/assets/000/065/276/medium800/feather_The_Things_Network_Console_2.png?1541611535)

On the **Register Device Page** ,&nbsp;The **Device ID** should be a unique string to identify the device.&nbsp;

The&nbsp; **Device EUI&nbsp;** is the unique identifier which came in the same bag as your Radiofruit Feather. We'll pad the middle of the string with four zeroes. Lost your key? No worries - you can also click the "mix" icon to switch it to auto-generate.

The&nbsp; **App Key&nbsp;** will be randomly generated for you by TTN. Select the **App EUI** (used to identify the application) from the list.

![](https://cdn-learn.adafruit.com/assets/assets/000/065/277/medium800/feather_The_Things_Network_Console_4.png?1541611564)

Next, we're going to switch the device settings from Over-the-Air-Activation to Activation-by-Personalization. From the Device Overview, **click Settings**

![](https://cdn-learn.adafruit.com/assets/assets/000/065/278/medium800/feather_The_Things_Network_Console_5.png?1541611643)

On the settings screen,&nbsp; **change the Activation Method from OTAA to ABP**.

&nbsp;

Then,&nbsp; **switch the Frame Counter Width from 32b to 16b** &nbsp;and&nbsp; **disable frame counter checks**. TTN will display a warning, ignore it, and&nbsp; **click Save**.

![feather_The_Things_Network_Console.png](https://cdn-learn.adafruit.com/assets/assets/000/065/281/medium640/feather_The_Things_Network_Console.png?1541611982)

![feather_The_Things_Network_Console_6.png](https://cdn-learn.adafruit.com/assets/assets/000/065/282/medium640/feather_The_Things_Network_Console_6.png?1541611997)

Warning: 

Now that the application is set up, and the device is registered to the application, let's move on to setting up Arduino with TinyLoRa.

### 

Disabling frame counter checks allows you to transmit data to The Things Network without requiring a match between your device's frame counter and the console's frame counter.

If you're making a project and doing a lot of prototyping/iteration to the code, disabling these checks is&nbsp;_okay_ as it'll let you reset the device and not re-register it to the application (it'll also prevent counter overflows).

If you're deploying a project, you'll want to re-activate the frame counter for security purposes. With the frame counter disabled, one could re-transmit the messages sent to TTN using a replay attack.&nbsp;

The Things Network's documentation page has&nbsp;[a full explanation about the role of the Frame Counter](https://www.thethingsnetwork.org/docs/lorawan/security.html#frame-counters).

# LoRa and LoRaWAN Radio for Raspberry Pi

## Usage

Danger: 

Danger: 

Now that we've set up our Things Network application and device, we're going to move on to installing [TinyLoRa](https://github.com/adafruit/Adafruit_CircuitPython_TinyLoRa/) onto our Raspberry Pi. To do this, **enter the following into your terminal to install the library** system-wide:

`sudo pip3 install adafruit-circuitpython-tinylora`

## Code

Unlike sending data to another device, we're going to be sending data from our device (the Pi) to a gateway ([check the gateway map to find one near you](https://www.thethingsnetwork.org/community)).

While we don't have any sensors hooked up to our radio, we'll send the Raspberry Pi's CPU utilization to The Things Network.

Below is an example of using TinyLoRa to send data to The Things Network. Save this as&nbsp; **radio\_lorawan.py** on your Raspberry Pi.&nbsp;

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/pi_radio/radio_lorawan.py

You'll also want to download the font file, **`font5x8.bin`,** and copy it&nbsp;into the same directory as the script:

[font5x8.bin](https://github.com/adafruit/Adafruit_CircuitPython_framebuf/blob/master/examples/font5x8.bin)
## Setting up the code for The Things Network

While we can send data to The Things Network, and our gateway might notice it, it isn't registered to a device yet. To register your device with The Things Network&nbsp; **using** &nbsp; **ABP** , you'll need to set three unique identifiers in **radio\_lorawan.py** : the&nbsp;`Network Session Key`, the&nbsp;`Device Address`, and the&nbsp;`Application Session Key`.

Navigate to the&nbsp; **Device Overview&nbsp;** page for your Raspberry Pi device.

&nbsp;

Make sure the&nbsp; **Activation Method** &nbsp;is set to&nbsp; **ABP**.&nbsp;

![pi_a___b___2__3_pi_zero_The_Things_Network_Console.png](https://cdn-learn.adafruit.com/assets/assets/000/068/456/medium640/pi_a___b___2__3_pi_zero_The_Things_Network_Console.png?1546275118)

Before adding the unique identifiers to our code, we'll need to first expand them by clicking the **\<\> icon.**

![](https://cdn-learn.adafruit.com/assets/assets/000/068/457/medium800thumb/pi_a___b___2__3_pi_zero_wireless_feather_keyexpandconsole.jpg?1546275151)

These are your keys. We're going to enter them into our&nbsp;code, but we need to&nbsp; **be careful** &nbsp;- the keys on the Things Network console use&nbsp; **parentheses or curly&nbsp;**** braces&nbsp;_{ }&nbsp;_instead of brackets&nbsp; **_** []**.&nbsp;_

First, copy the&nbsp; **Device Address** &nbsp;from the TTN console to the&nbsp;`devaddr` **&nbsp;** variable in the code.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/068/458/medium800/pi_a___b___2__3_pi_zero_wireless_device_Addr.png?1546275183)

Then,&nbsp; **remove the braces&nbsp;_{ }_** &nbsp;from the device address.

A device address copied from The Things Network console would look like:&nbsp;`{ 0x26, 0x02, 0x1F, 0x07 }`.&nbsp;In the code, it'd look like:&nbsp;`devaddr = bytearray([0x26, 0x02, 0x1F, 0x07])`.

![](https://cdn-learn.adafruit.com/assets/assets/000/068/459/medium800/pi_a___b___2__3_pi_zero_wireless_device_addr_python.png?1546275263)

Then, copy the&nbsp; **Network Session Key** &nbsp;from the TTN console to the `nwkey` **&nbsp;** variable in the code. Make sure to modify the code to remove the parentheses/curly braces { }.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/068/460/medium800/pi_a___b___2__3_pi_zero_wireless_nwkey.png?1546275344)

Finally, copy the&nbsp; **Application Session Key** &nbsp;from the TTN console to the&nbsp;`app` **&nbsp;** variable in the code.&nbsp;Make sure to modify the code to remove the parentheses/curly braces { }.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/068/461/medium800/pi_a___b___2__3_pi_zero_wireless_appskey.png?1546275367)

That's all for now - we're ready to run our code!&nbsp;

## Usage

**Enter the following into the terminal** and **press enter** :

**`python3 radio_lorawan.py`**

The OLED should display the operating mode (LoRaWAN).

![raspberry_pi_IMG_5459.jpg](https://cdn-learn.adafruit.com/assets/assets/000/069/488/medium640/raspberry_pi_IMG_5459.jpg?1547677423)

 **Press Button A to send this data** to the The Things Network application you built earlier.

![raspberry_pi_lorawan_send.gif](https://cdn-learn.adafruit.com/assets/assets/000/069/489/medium640thumb/raspberry_pi_lorawan_send.jpg?1547677487)

 **Press Button B** &nbsp;to view the Raspberry Pi's CPU utilization percentage.

![raspberry_pi_raspi_cpu_load.gif](https://cdn-learn.adafruit.com/assets/assets/000/069/567/medium640thumb/raspberry_pi_raspi_cpu_load.jpg?1547763113)

 **Pressing Button C** will periodically send a packet to the things network. You can modify this value (in seconds) by changing the `data_pkt_delay` variable in the code.

![raspberry_pi_Lora_mode_periodic.gif](https://cdn-learn.adafruit.com/assets/assets/000/069/568/medium640thumb/raspberry_pi_Lora_mode_periodic.jpg?1547763153)

## Checking Data on The Things Network Console

We want to make sure the data has been received on the other end. To do this, we'll navigate to the The Things Network Console and select the&nbsp; **application**. From the menu on the right hand side of the page, click&nbsp; **Data**.

If everything worked correctly, you'll see the payload from your device streaming into the page, in real time.&nbsp;

Neat,&nbsp;right? But while we received a payload, we still don't understand what it means. It's been sent to The Things Network and&nbsp;_decoded_&nbsp;on the client (Gateway) side, so it's not an AES-encrypted payload anymore. It's just not readable by humans.

## Decoding the Payload

If you're sending packets in strange formats or encodings (like we are!), The Things Network Console has a&nbsp;[programmable data decoder](https://www.thethingsnetwork.org/docs/devices/bytes.html)&nbsp;to decode the packets, and assign useful labels to the data.

**Copy and paste the decoder script** &nbsp;below into the decoder's integrated text editor and&nbsp; **click save**.&nbsp;

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/pi_radio/ttn_decoder_lorawan.js

![](https://cdn-learn.adafruit.com/assets/assets/000/068/463/medium800thumb/pi_a___b___2__3_pi_zero_wireless_feather_add_decoder.jpg?1546275767)

Then,&nbsp; **click the data tab**. Next to the raw payload data, you should see the decoded data for the CPU load.

![](https://cdn-learn.adafruit.com/assets/assets/000/068/462/medium800thumb/pi_a___b___2__3_pi_zero_ezgif.com-video-to-gif_%282%29.jpg?1546275485)


## Featured Products

### Raspberry Pi 3 - Model B+ - 1.4GHz Cortex-A53 with 1GB RAM

[Raspberry Pi 3 - Model B+ - 1.4GHz Cortex-A53 with 1GB RAM](https://www.adafruit.com/product/3775)
The Raspberry Pi 3 Model B is the most popular Raspberry Pi computer made, and the Pi Foundation knows you can always make a good thing _better_! And what could make the Pi 3 better? How about a&nbsp;_faster_ processor, 5 GHz WiFi, and updated Ethernet chip with PoE capability?...

In Stock
[Buy Now](https://www.adafruit.com/product/3775)
[Related Guides to the Product](https://learn.adafruit.com/products/3775/guides)
### Raspberry Pi Zero - Version 1.3

[Raspberry Pi Zero - Version 1.3](https://www.adafruit.com/product/2885)
At first glance, the Pi Zero isn't much. &nbsp;It just looks like a slimmed down version of the Raspberry Pi we know and love. &nbsp;But when we started to think of the possibilities - [and what a well-chosen set of accessories could add](https://www.adafruit.com/product/2816) -...

In Stock
[Buy Now](https://www.adafruit.com/product/2885)
[Related Guides to the Product](https://learn.adafruit.com/products/2885/guides)
### Adafruit LoRa Radio Bonnet with OLED - RFM95W @ 915MHz

[Adafruit LoRa Radio Bonnet with OLED - RFM95W @ 915MHz](https://www.adafruit.com/product/4074)
The latest Raspberry Pi computers come with WiFi and Bluetooth®, and now you can add even more radio options with the Adafruit Radio Bonnets! Upgrade your Raspberry Pi with a LoRa/LoRaWAN radio so it can communicate over very long distances. These bonnets plug right into your Pi and give...

In Stock
[Buy Now](https://www.adafruit.com/product/4074)
[Related Guides to the Product](https://learn.adafruit.com/products/4074/guides)
### Adafruit LoRa Radio Bonnet RFM96W @ 433MHz

[Adafruit LoRa Radio Bonnet RFM96W @ 433MHz](https://www.adafruit.com/product/4075)
The latest Raspberry Pi computers come with WiFi and Bluetooth, and now you can add even more radio options with the Adafruit Radio Bonnets! Upgrade your Raspberry Pi with a LoRa / LoRaWAN radio, so it can communicate over very long distances. These bonnets plug right into your Pi and give you...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/4075)
[Related Guides to the Product](https://learn.adafruit.com/products/4075/guides)
### Adafruit RFM95W LoRa Radio Transceiver Breakout - 868 or 915 MHz

[Adafruit RFM95W LoRa Radio Transceiver Breakout - 868 or 915 MHz](https://www.adafruit.com/product/3072)
_"You see, wire telegraph is a kind of a very, very long cat.&nbsp; You pull his tail in New York and his head is meowing in Los Angeles.&nbsp; Do you understand this? And radio operates exactly the same way: you send signals here, they receive them there.&nbsp; The only difference is..._

In Stock
[Buy Now](https://www.adafruit.com/product/3072)
[Related Guides to the Product](https://learn.adafruit.com/products/3072/guides)
### Adafruit RFM96W LoRa Radio Transceiver Breakout - 433 MHz

[Adafruit RFM96W LoRa Radio Transceiver Breakout - 433 MHz](https://www.adafruit.com/product/3073)
_"You see, wire telegraph is a kind of a very, very long cat.&nbsp; You pull his tail in New York and his head is meowing in Los Angeles.&nbsp; Do you understand this? And radio operates exactly the same way: you send signals here, they receive them there.&nbsp; The only difference is..._

Out of Stock
[Buy Now](https://www.adafruit.com/product/3073)
[Related Guides to the Product](https://learn.adafruit.com/products/3073/guides)
### Assembled Pi T-Cobbler Plus - GPIO Breakout

[Assembled Pi T-Cobbler Plus - GPIO Breakout](https://www.adafruit.com/product/2028)
 **This is the assembled version of the Pi T-Cobbler Plus. &nbsp;It only works with the Raspberry Pi Model Zero, A+, B+, Pi 2, Pi 3 & Pi 4!** (Any Pi with 2x20 connector)  
  
The Raspberry Pi has landed on the Maker World like a 40-GPIO pinned, quad-USB ported, credit...

In Stock
[Buy Now](https://www.adafruit.com/product/2028)
[Related Guides to the Product](https://learn.adafruit.com/products/2028/guides)
### Monochrome 128x32 I2C OLED graphic display

[Monochrome 128x32 I2C OLED graphic display](https://www.adafruit.com/product/931)
These displays are small, only about 1" diagonal, but very readable due to the high contrast of an OLED display. This display is made of 128x32 individual white OLED pixels, each one is turned on or off by the controller chip. Because the display makes its own light, no backlight is...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/931)
[Related Guides to the Product](https://learn.adafruit.com/products/931/guides)

## Related Guides

- [Adafruit Radio Bonnets with OLED Display - RFM69 or RFM9X](https://learn.adafruit.com/adafruit-radio-bonnets.md)
- [Playing sounds and using buttons with Raspberry Pi](https://learn.adafruit.com/playing-sounds-and-using-buttons-with-raspberry-pi.md)
- [Using LoraWAN and The Things Network with CircuitPython](https://learn.adafruit.com/using-lorawan-and-the-things-network-with-circuitpython.md)
- [Windows IoT Core Application Development: Headless Blinky](https://learn.adafruit.com/windows-iot-application-development-headless-application.md)
- [Feather + Raspberry Pi Weather Monitoring Network with LoRa or LoRaWAN](https://learn.adafruit.com/multi-device-lora-temperature-network.md)
- [CircuitPython Libraries on Linux and ODROID C2](https://learn.adafruit.com/circuitpython-libaries-linux-odroid-c2.md)
- [Windows IoT Core Application Development: Headed Blinky](https://learn.adafruit.com/windows-iot-application-development-headed-blinky.md)
- [Single Channel LoRaWAN Gateway for Raspberry Pi](https://learn.adafruit.com/raspberry-pi-single-channel-lorawan-gateway.md)
- [Adafruit RFM69HCW and RFM9X LoRa Packet Radio Breakouts](https://learn.adafruit.com/adafruit-rfm69hcw-and-rfm96-rfm95-rfm98-lora-packet-padio-breakouts.md)
- [Analog Inputs for Raspberry Pi Using the MCP3008](https://learn.adafruit.com/reading-a-analog-in-and-controlling-audio-volume-with-the-raspberry-pi.md)
- [Adafruit's Raspberry Pi Lesson 13. Power Control](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-13-power-control.md)
- [Capacitive Touch Sensors on the Raspberry Pi](https://learn.adafruit.com/capacitive-touch-sensors-on-the-raspberry-pi.md)
- [Raspberry Pi E-mail Notifier Using LEDs](https://learn.adafruit.com/raspberry-pi-e-mail-notifier-using-leds.md)
- [Adafruit's Raspberry Pi Lesson 11. DS18B20 Temperature Sensing](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-11-ds18b20-temperature-sensing.md)
- [Adafruit AMG8833 8x8 Thermal Camera Sensor](https://learn.adafruit.com/adafruit-amg8833-8x8-thermal-camera-sensor.md)
- [Automatic Naughty Cat Detector using Lobe](https://learn.adafruit.com/naughty-cat-detector-using-microsoft-lobe.md)
