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.

Owner
Alasdair Allan
Scientist, Author, Hacker, Tinkerer, Maker and Journalist. Is responsible for the Raspberry Pi documentation.
Alasdair Allan
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

Furkan Enes POLATOĞLU 6 Dec 13, 2022
HomeAssistant - Polyaire AirTouch 4 Integration

HomeAssistant - Polyaire AirTouch 4 Integration Custom integration to add an AirTouch 4 AC Controller Installation: Copy contents of custom_components

7 Aug 05, 2022
Python library for the Phomemo m02s bluetooth thermal printer

Phomemo M02S Python library This is a basic Python library for controlling the Phomemo M02S bluetooth thermal printer. It probably only works on Mac &

Stargirl Flowers 28 Nov 07, 2022
Parametric open source reconstructions of Voron printed parts

The Parametric Voron This repository contains Fusion 360 reconstructions of various printed parts from the Voron printers

Matthew Lloyd 26 Dec 19, 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

3 Feb 21, 2022
A python script for Homeassistant that counts down the days to birthdays, anniversaries etc

Date Countdown A python script for Homeassistant that counts down the days to birthdays, anniversaries etc Important note I no longer use homeassistan

Marc Forth 21 Mar 12, 2022
Add filters (background blur, etc) to your webcam on Linux.

webcam-filters Add filters (background blur, etc) to your webcam on Linux. Video conferencing applications tend to either lack video effects altogethe

Jashandeep Sohi 480 Dec 14, 2022
A raspberrypi tools for python

raspberrypi-tools how to install: first clone this project: git clone https://github.com/Ardumine/rpi-tools.git then go to the folder cd rpi-tools and

1 Jan 04, 2022
Cow Feeder is a bot automatically execute trade on cowswap

Cow Feeder is a bot automatically execute trade on cowswap, includes functions: Monitoring Ethereum network gas price and execute trade whe

6 Apr 20, 2022
🌱 - WebhookHard◞ Fines Educativos ◟

v1.0.0 WebhookHardware ¿Que es WebhookHardware? WebhookHardware se trata de un proyecto tratado para sacar informacion sobre el hardware de tus victim

3 Jun 14, 2021
Simple Microservice to control 433Mhz wireless sockets over HTTP, e.g. on a RaspberryPi

REST-light is a simple microservice to control 433Mhz wireless sockets over HTTP, e.g. on a RaspberryPi. The main usage is an easy integration of 433M

Pascal Höhnel 1 Jan 09, 2022
Robot Framework keyword library wrapper for atlassian-python-api

Robot Framework keyword library wrapper for atlassian-python-api

Marcin Koperski 3 Jul 29, 2022
The robot is an autonomous small scale racing car using NVIDIA Jetson Nano.

The robot is an autonomous small scale racing car using NVIDIA Jetson Nano. This project utilizes deep learning neural network framework Keras/Tensorflow, together with computer vision library OpenCV

1 Dec 08, 2021
Resmed_myair_sensors - This is a Home Assistant custom component to pull daily CPAP data from ResMed's myAir service using an undocumented API

resmed_myair This component will set up the following platforms. Platform Description sensor Show info from the myAir API. Installation Using the tool

Preston Tamkin 17 Dec 29, 2022
Python apps to assist with Gas Blending

Welcome to DiveTools Gas Blending This tool is for testing and educational use. It is not intended to confirm the mix of breathing gases. If this tool

Tucker 7 Sep 18, 2022
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

Kevin Thomas 5 Feb 02, 2022
Home Assistant custom integration for Yi cameras: yi-hack-MStar, yi-hack-Allwinner and yi-hack-Allwinner-v2

yi-hack Home Assistant integration Overview yi-hack Home Assistant is a custom integration for Yi cameras (or Sonoff camera) with one of the following

roleo 131 Jan 03, 2023
Raspberry Pi Spectrometer

PySpectrometer 2021-03-05 Raspberry Pi Spectrometer The PySpectrometer is a Python (OpenCV and Tkinter) implementation of an optical spectrometer. The

Les Wright 538 Jan 05, 2023
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

BeBoXoS 3 Nov 14, 2021
Brogrammer-keyboard - FIrmware for the Brogrammer Keyboard v1.0

Brogrammer Keyboard Firmware The package contains the firmware that runs on the Brogrammer Keyboard v1.0 See https://imgur.com/a/oY5QZ14 This keyboard

Devin Hartleben 1 Apr 21, 2022