Raspberry Pi Pico and LoRaWAN from CircuitPython

Overview

Raspberry Pi Pico and LoRaWAN from CircuitPython

Hero image

Enable LoRaWAN communications on your Raspberry Pi Pico or any RP2040-based board using CircuitPython and the Adafruit TinyLoRa library. Based on the TinyLoRa example code by Adafruit.

Bill of Materials

The following hardware is needed:

Item Link
Raspberry Pi Pico https://www.raspberrypi.org/products/raspberry-pi-pico/
Adafruit RFM95x Lora Radio https://www.adafruit.com/product/3072
Edge-Mount SMA Connector https://www.adafruit.com/product/1865
868MHz or 915MHz Antenna https://www.adafruit.com/product/3340
Male-Female Jumper Wires https://www.adafruit.com/product/1953
Breadboard https://www.adafruit.com/product/64

Wiring the RFM9x Radio Module

Wiring diagram

After soldering your RFM95x module and attaching an antenna the mapping between the pins on the module breakout board and your Pico should be as follows:

Pico RP2040 SX1276 Module RFM95W Breakout
3V3 (OUT) VCC VIN
GND GND GND GND
Pin 10 GP7 DIO0 G0
Pin 11 GP8 NSS CS
Pin 12 GP9 RESET RST
Pin 14 GP10 DIO1 G1
Pin 21 GP16 (SPI0 RX) MISO MISO
Pin 24 GP 18 (SPI0 SCK) SCK SCK
Pin 25 GP19 (SPI0 TX) MOSI MOSI

The Things Network

To make use of a LoraWAN-enabled Pico you’re going to need to be in range of a LoRa gateway. Fortunately there is The Things Network, an open-source community LoRaWAN network that has global coverage. Depending on where you are located, it’s quite possible that you’re already in coverage. However, if you aren’t, then you needn’t worry too much, the days when the cost of a LoRaWAN base station was of the order of several thousand dollars are long gone. You can now pick up a LoRa gateway for under $100.

While any LoRa device in range of your new gateway will have its packets received and sent upstream to The Things Network, the data packets will be dropped on the ground unless they have somewhere to go. In other words, The Things Network needs to know where to route the packets your gateway is receiving.

Setting up The Things Network

Adafruit has written up a full walkthrough on how to set up and application and register your device with The Things Network. You'll need to set three unique identifiers in the code.py file; the Device Address, Network Session Key, and Application Session Key. These can be found on the Device Overview page.

NOTE: The example code uses ABP rather than OTAA as the Activation Method.

Deploying to your Pico

Copy the contents of the src/ directory in the repo to your CIRCUITPY drive. This includes the code.py file and the lib/ folder and all of its contents, including subfolders and any .mpy files present in the library directory.

Sending data

Restart the board. The code should start running immediately, there will be debug output available on the USB CDC Serial console. If you see "Packet Sent!" then the packets are being sent up to The Things Network via LoRaWAN and you should be able to see your data arriving in the Network Console.

Adding a decoder

We're sending out temperature reading as a byte array.

temp = microcontroller.cpu.temperature
temp = int(temp * 100)

data = bytearray(2)
data[0] = (temp >> 8) & 0xFF
data[1] = temp & 0xFF

By default the payload is displayed as a hexidecimal values in the Network Console. However we can add a data decoder;

function Decoder(bytes, port) {
  var decoded = {};
  var celciusInt = (bytes[0] << 8) | bytes[1];
  decoded.temp = celciusInt / 100;

  return decoded;

this will auto-magically decode the raw payload and display the real value in The Things Network Console.

More information

You can find more information about using LoRaWAN and The Things Network from CircuitPython in the Adafruit RFM95x tutorial pages. Alternatively you may want to use the RFM95x module using C, in which case you should take a look at Sandeep Mistry's pico-lorawan library, and getting started instructions.

Libraries

The following libraries are used:

Library License Github
Bus Device MIT https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
RFM95x MIT https://github.com/adafruit/Adafruit_CircuitPython_RFM9x
TinyLoRa LGPL https://github.com/aallan/pico-lorawan-circuitpython

License

This software is released under the MIT License.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

You might also like...
A Raspberry Pi Pico plant sensor hub coded in Micropython

plantsensor A Raspberry Pi Pico plant sensor hub coded in Micropython I used: 1x Raspberry Pi Pico - microcontroller 1x Waveshare Pico OLED 1.3 - scre

Raspberry Pi Pico Escape Room game.
Raspberry Pi Pico Escape Room game.

Pico Escape Room Raspberry Pi Pico Escape Room game. Parts Raspberry Pi Pico Set of 2 x 20-pin Headers for Raspberry Pi Pico 4PCS Breadboards Kit Incl

An open source operating system designed primarily for the Raspberry Pi Pico, written entirely in MicroPython
An open source operating system designed primarily for the Raspberry Pi Pico, written entirely in MicroPython

PycOS An open source operating system designed primarily for the Raspberry Pi Pico, written entirely in MicroPython. "PycOS" is an combination of the

Turn your Raspberry Pi Pico into a USB Rubber Ducky
Turn your Raspberry Pi Pico into a USB Rubber Ducky

pico-ducky Turn your Raspberry Pi Pico into a USB Rubber Ducky Install Requirements CircuitPython for the Raspberry Pi Pico adafruit-circuitpython-bun

Play music on Raspberry Pi Pico Without CPU involvement

MicroPython_PIO_Music_DMA Play music on Raspberry Pi Pico Without CPU involvement This is based on PIOBeep (https://github.com/benevpi/pico_pio_buzz)

Raspberry Pi Pico as a Rubber Ducky
Raspberry Pi Pico as a Rubber Ducky

Raspberry-Pi-Pico-as-a-Rubber-Ducky Kurulum Raspberry Pi Pico cihazınız için CircuitPython'u indirin. Boot düğmesine basılı tutarken cihazı bir USB ba

CircuitPython library for the CH559 USB to Serial chip
CircuitPython library for the CH559 USB to Serial chip

CH559 (USB to Serial) CircuitPython Library Why? Because you might want to get keyboard/mouse/gamepad/HID input into your CircuitPython projects witho

circuitpython version of PyBasic for microcontrollers
circuitpython version of PyBasic for microcontrollers

cPyBasic Circuitpython version of PyBasic for microcontrollers Current version work only for Adafruit titano & CardKB for now. The origninal PyBasic w

A Python program that makes it easy to manage modules on a CircuitPython device!
A Python program that makes it easy to manage modules on a CircuitPython device!

CircuitPython-Bundle-Manager-v2 A Python program that makes it easy to manage modules on a CircuitPython device! The CircuitPython Bundle Manager v2 i

Comments
  • Pico-LoRa-SX1262 Support

    Pico-LoRa-SX1262 Support

    Hi Allan Please forgive my lack of knowledge, but would it be possible to use this example with Pico-LoRa-SX1262 from Waveshare ? I have been trying to get these modules to read a serial sensor ( https://wiki.dfrobot.com/A01NYUB%20Waterproof%20Ultrasonic%20Sensor%20SKU:%20SEN0313 ) which outputs a simplex constant 9600 baud stream. Which I want to send 1 read to the TTN twice a day. In python it looks much easier, though I don't know how to add SX1262 support to your code.

    Thank You very much . Greg.

    opened by gomond 0
Owner
Alasdair Allan
Scientist, Author, Hacker, Tinkerer, Maker and Journalist. Is responsible for the Raspberry Pi documentation.
Alasdair Allan
New armachat based on Raspberry Pi PICO an Circuitpython code

Armachat-circuitpython New Armachat based on Raspberry Pi PICO an Circuitpython code Software working features: send message with header and store to

Peter Misenko 44 Dec 24, 2022
Hourglass on the pi pico using circuitpython

hourglass-on-pico "Hourglass" on the raspberry pi pico using circuitpython circuitpython version 7.0.0 Components used: Raspberry Pi Pico ADXL345 acce

null 4 Jul 18, 2022
Pylorawan is a Micropython wrapper for lorawan devices from RAK Wireless.

pylorawan Pylorawan is a Micropython wrapper for lorawan devices from RAK Wireless. Tested on a Raspberry PI Pico with a RAK4200(H) Evaluation Board (

Peter Houghton 3 Nov 4, 2022
A rubiks cube timer using a distance sensor and a raspberry pi 4, and possibly the pi pico to reduce size and cost.

distance sensor cube timer A rubiks cube timer using a distance sensor and a raspberry pi 4, and possibly the pi pico to reduce size and cost. How to

null 3 Feb 21, 2022
A Raspberry Pi Pico powered Macro board, like a Streamdeck but cheaper and simpler.

Env-MCRO A Raspberry Pi Pico powered Macro board, like a Streamdeck but cheaper and simpler. (btw this image is a bit outdated, some of the silkscreen

EnviousData 68 Oct 14, 2022
A simple portable USB MIDI controller based on Raspberry-PI Pico and a 16-button keypad, written in Circuit Python

RPI-Pico-16-BTn-MIDI-Controller-using-CircuitPython A simple portable USB MIDI controller based on Raspberry-PI Pico, written in Circuit Python. Link

Rounak Dutta 3 Dec 4, 2022
a library for using WS2812b leds (aka neopixels) with Raspberry Pi Pico

pico_ws2812b a library for using WS2812b leds (aka neopixels) with Raspberry Pi Pico You'll first need to save the ws2812b.py file to your device (for

null 76 Nov 25, 2022
A Python class for controlling the Pimoroni RGB Keypad for Raspberry Pi Pico

rgbkeypad A Python class for controlling the Pimoroni RGB Keypad for the Raspberry Pi Pico. Compatible with MicroPython and CircuitPython. keypad = RG

Martin O'Hanlon 43 Nov 11, 2022
Raspberry Pi Pico development platform for PlatformIO

Raspberry Pi Pico development platform for PlatformIO A few words in the beginning Before experimental please Reinstall the platform Version: 1.0.0 Th

Georgi Angelov 160 Dec 23, 2022
Raspberry Pi Pico support for VS Code

Pico-Go VS Code Extension Pico-Go provides code auto-completion and allows you to communicate with your Raspberry Pi Pico board using the built-in REP

Chris Wood 114 Dec 28, 2022