collins emasi
Published © CC BY

How to design and deploy a LoRa IoT sensor node with RP2040

In this project, we will be developing an IoT sensor node. We'll start with PCB design, manufacturing, programming and finally testing it.

BeginnerFull instructions provided1,168
How to design and deploy a LoRa IoT sensor node with RP2040

Things used in this project

Hardware components

Seeed XIAO RP2040
Seeed Studio Seeed XIAO RP2040
Seeed Studio - Wio-E5 Wireless Module
DFRobot SHT31 - High accuracy Temp & Humidity Sensor

Software apps and online services

Flux is a better way to build PCBs
VS Code
Microsoft VS Code

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Flux, Soldering
Solder Flux, Soldering
Solder Paste, Rework
Solder Paste, Rework


Read more


Functions that send AT commands and uplinks

The first function "send_at_command" is used to talk to the LoRa module. "send_msghex" sends an uplink to lorawan
# This function sends an AT command to the LoRa module
def send_at_command(command, response_timeout=5000):
    uart.write(command + b'\r\n')

# This function sends hex data and blinks the onboard RGB LED when successfully sent
def send_msghex(hex_data):
    command = b'AT+MSGHEX=' + hex_data
    response = send_at_command(command)
    if "ERROR" not in response:
    if "FPENDING" in response:
        print("Downlink Received!")

Main File

This is the main code
import time
import machine
from machine import Pin, I2C, deepsleep

import SHT31
from lora_lib import configure_lora_module, send_msghex

# Define firmware parameters
UPLINK_INTERVAL = 60000         # In milliseconds

# Configure SHT31 Sensor
i2c = I2C(id=1, scl=Pin(7), sda=Pin(6), freq =400000)
sensor = SHT31.SHT31(i2c, addr=0x44)

while True:
    if FIRST_TIME:
        # Configure LoRa Module
        status = configure_lora_module()
        FIRST_TIME = False

    # Read sensor data
    temp_humi = sensor.get_temp_humi()
    humidity = temp_humi[1]
    temperature = temp_humi[0]

    # Convert into hex for transmission
    sensor_data_hex = f'{int(humidity * 100):04x}{int(temperature * 100):04x}'

    # Transmit data

    # Sleep for UPLINK INTERVAL (adjust as needed)
    print(f"Temperature: {temperature}")
    print(f"Humidity: {humidity}")

Generating device EUI

Generating the device EUI
# Generating the Device EUI
import secrets

dev_eui = secrets.token_hex(8).upper()
print("DevEui:", dev_eui)

# Reading it
dev_eui = read_id(b'DevEui')
print("DevEui:", dev_eui)


collins emasi

collins emasi

1 project • 3 followers
Electronics Engineer