How to connect a Raspberry Pi Pico to LoRaWAN

LoRaWAN is a long-range, low-power protocol with a low bandwidth. With a good antenna, you might get 15 kilometres of range from an off-the-shelf LoRa radio, which is intended to link battery-powered remote sensors to the internet through a gateway. In the negative side, usable bandwidth would be calculated in bytes rather than megabytes or even kilobytes.

Sandeep Mistry, the author of the Arduino LoRa library, who also recently added Ethernet support for Pico, put together support for LoRa compatibility for Pico. Using the Semtech SX1276 radio module, his library adds LoRa support to Pico and other RP2040-based boards. As a result, breakout boards such as Adafruit’s RFM95W and LoRa FeatherWing are completely supported.

Is there any LoRaWAN coverage?

You’ll need to be within range of a LoRa gateway to use a LoraWAN-enabled Pico. The Things Network, an open-source community LoRaWAN network with worldwide reach, comes to the rescue.

It’s likely that you’re already covered, depending on where you’re based. If you aren’t, though, you shouldn’t be too concerned.

The days when a LoRaWAN base station will set you back several thousand dollars are long gone. A LoRa portal is now available for around £75. However, a few years ago, created my own portal. Perhaps unsurprisingly, it was built around a Raspberry Pi.

Obtaining a source

Make sure your pico-sdk checkout, including submodules, is up to date if you already have the Raspberry Pi Pico toolchain installed and running. If not, you’ll need to first instal the C/C++ SDK before downloading the project from GitHub.

git clone — recurse-submodules cd pico_lorawan

Before continuing, double-check that your PICO_SDK_PATHis fixed. If you're using a Raspberry Pi and have run the script or followed the directions in Pico Getting Started guide, for example, you'd set the PICO_SDK_PATH to

export PICO_SDK_PATH = /home/pi/pico/pico-sdk

After that, both the library and the sample programmes are ready to be developed. But first, we’ll need to setup the cloud infrastructure where our data will be stored, as well as link our LoRa radio board to our Raspberry Pi Pico.

Create a programme.

Although every LoRa system in range of the new gateway will have its packets collected and sent upstream to The Things Network, data packets will be dumped on the ground because they have a destination. In other words, The Things Network must know where to redirect the packets received by the gateway.

To provide it with this knowledge, we must first construct an application inside The Things Network Console. To do this, simply enter a specific Application ID string — whatever will do — and the console will create an Application EUI and a default Access Key, which we will use to register our devices to our application.

If we’ve registered an application, what we have to do is register our particular device — or, in the future, a group of devices — to that application so that the backend knows where to route packets from that device.

Device Registration

The application’s page in the console can be used to register our computer.

Our remote device is identified by the Device ID, which is a human-readable string. Since the Adafruit RFM9W breakout board comes with a sticker in the same bag as the radio with a special identifier written on it, we can use it to postpend a string to uniquely mark our Pico board, so we end up with something like pico-xy-xy-xy-xy-xy-xy

In addition, we’ll need to create a Device EUI 2. This is a 64-bit one-of-a-kind identifier. To produce our Device EUI, we can once again use the unique identifier from the sticker, except this time we can simply pad it with two leading zeros, 0000XYXYXYXYXYXY To create the Device EUI, you may also use pico_get_unique_board_id( ).

If you look at your Device page after registration, you’ll see that you’ll need the Application EUI2 and Application Key2 to allow your board to communicate with the LoRa network, or more specifically, to allow the network to correctly route packets from your board to your application.

2 Write down your Device EUI, Application EUI, and Application Key.

Putting items together on a breadboard

After we’ve configured our cloud backend, the next step is to bind our Pico to the LoRa breakout board. Unfortunately, the RFM95W breakout is not designed to be used on a breadboard. At the very least, it’s not breadboard-friendly if you need access to the radio’s pins on both sides of the board, like we do with this project — the breakout is just a tad too big for a normal breadboard in this situation.

Fortunately, it is not a major issue, but you would most likely need to obtain a number of male-to-female jumper wires in addition to your breadboard. Connect the RFM95W module to your Raspberry Pi Pico now. The pin mapping between the breakout board’s pins and your Pico should be as follows:

Physical pin mapping, RP2040 pin mapping, SX1276 module mapping, and RFM95W This are the library’s default pins, which can be modified in apps.

Computer development and deployment

Now that we’ve set up our backend in the cloud and physically “made” our antenna, we can develop and deploy our LoRaWAN programme. One of the library’s example applications can read the temperature from the on-chip sensor on the RP2040 microcontroller and transmit it to the Things Network application on a regular basis via the LoRaWAN radio.

void internal_temperature_init() { adc_init(); adc_select_input(4); adc_set_temp_sensor_enabled(true); } float internal_temperature_get() { float adc_voltage = adc_read() * 3.3f / 4096; float adc_temperature = 27 - (adc_voltage - 0.706f) / 0.001721f; return adc_temperature; }

Shift the directory in your checkout to the otaa_temperature_led sample programme. Since this example employs OTAA, we’ll need the Device EUI, Application EUI, and Application Key that we created.


Adjust the Area, REGION, DEVICE_EUI, APP_EUI values in the config.h file to the values displayed in the Network Console. Instead of the byte array representation, the code expects the (default) string format, with no spaces between the hexadecimal digits.

#define LORAWAN_REGION LORAMAC_REGION_EU868 #define LORAWAN_DEVICE_EUI “Insert your Device EUI” #define LORAWAN_APP_EUI “Insert your Application EUI” #define LORAWAN_APP_KEY “Insert your App Key” #define LORAWAN_CHANNEL_MASK NULL

I’m in the United Kingdom, and my LoRa radio broadcasts at 868MHz, so I’ll set my region to LORAMAC_REGION_EU868. If you live in the United States, you must set your country to LORAMAC_REGION_US915.

After you’ve modified the config.h file, you may proceed to construct the sample applications.

If all goes well, you should have a UF2 file named pico_lorawan_otaa_temperature_led.uf2 in build/examples/otaa_temperature_led/. You can now load this UF2 file into your Pico as normal.

Take your Raspberry Pi Pico board and a micro USB cable with you. Connect the cable to your Raspberry Pi or laptop, and then press and hold the BOOTSEL button on your Pico while inserting the other end of the micro USB cable into the board. Then, once the board is plugged in, release the switch.

RPI-RP2 can appear as a disc volume on your desktop. To open it, double-click it and then drag and drop the UF2 file into it. If you are experiencing difficulties, please see Chapter 4 of our Getting Started guide for more details.

Your Pico is now running your LoRaWAN programme, and if you open a USB Serial link to it, you should be able to see some debugging stuff. Start minicom in a Terminal pane.

Data Transmission

To see the true information, however, you must go to the Network console. An initial join message should be shown, followed by a series of frames. Each frame represents a temperature measurement sent from your Pico to The Things Network application through LoRaWAN and the Gateway.

The payload value is the hexadecimal temperature determined by the Raspberry Pi Pico’s internal temperature sensor. It’s a little beyond the reach of this post, but you can now add a decoder and integrations that enable you to decrypt hexadecimal data into human-readable data and then save it to a database, among other things. To demonstrate the strength of what you can do here, go to your application’s “Payload Formats” tab and enter the following Javascript in the “decoder” box:

Scroll down and press the green “save payload functions” button.

Returning to the “Data” tab, you can note that the payload, in hexidecimal, is now post-pended with the temperature in degrees Celsius. Our basic decoder has converted our payload back into a Javascript object.

Sending commands

Go to the Network Console’s Device tab and type “01” into the Downlink Payload box before clicking the “Send” button. Then choose the Data column. You should see a line that says “Download planned,” and if you keep an eye on it, you should see the byte downlinked. When this occurs, the on-board LED on your Raspberry Pi Pico can illuminate! Returning to the Network Console and entering “00” into the Payload box would (at some point) switch off the Pico’s LED.

Keep in mind that LoRaWAN has a long range but a limited bandwidth. A downlinked order should not be expected to be responded to immediately.

The OTAA example framework is a great starting point for you to build on, as it allows you to take data and send it to the cloud via LoRa, as well as send commands back from the cloud to your LoRa-enabled Pico.

During this week’s Arm Innovation Coffee on Thursday at 10:00 a.m. PDT (18:00 a.m. BST), there will be more talk about the Things Network and a live demonstration of LoRaWAN from a Raspberry Pi Pico (29 April).

Finishing up

The Raspberry Pi forums provide development support for Pico. There is also a (unofficial) Discord server where several members of the group tend to congregate. Feedback on the documents should be submitted as an Issue to the pico-feedback repository on GitHub, or to the repository in question directly.

The Getting Started page contains all of the documentation, as well as a wealth of other resources and connections. If you lose track of where it is in the future, you can still access it from your Pico: simply press and hold the BOOTSEL button on your Pico, plug it into your laptop or Raspberry Pi, and then release the button to access the website. Open the RPI-RP2 volume and then double-click the INDEX.HTM file.

This will still redirect you to the Getting Started tab.

Credit: Alasdair Allan

Originally published at




Tech Writer | Maker of Random Contraptions | Education | Learning — #Robotics #RaspberryPi #DIYElectronics

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Four More Days

DevOps Insights [Part 1]: It’s all about the Flow

Exploring LiveData and Kotlin Flow

What Happened Today?

Kubernetes Garbage Collection

What?! @WSGToken’s new game is here! 🔥🕹️

JiFinance (JIF) Launchpool Development Update

How much does Tinder cost?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
DIY Electronics

DIY Electronics

Tech Writer | Maker of Random Contraptions | Education | Learning — #Robotics #RaspberryPi #DIYElectronics

More from Medium

How to Install the Windows Subsystem for Linux on Windows 11 and setup for Competitive Programming

Mosquitto MQTT Broker Raspberry Pi

Install a new Kernel in Gentoo

compiling the Kernel

Getting Started with the Raspberry Pi