• sales

    +86-0755-88291180

RP2040-LoRa Guide

Resource

Document

Demo

Datasheet

Development Software

Pico Quick Start

Download Firmware

  • MicroPython Firmware Download
  • C_Blink Firmware Download

Video Tutorial

  • Pico Tutorial I - Basic Introduction
  • Pico Tutorial II - GPIO
  • Pico Tutorial III - PWM
  • Pico Tutorial IV - ADC
  • Pico Tutorial V - UART
  • Pico Tutorial VI - To be continued...

MicroPython Series

C/C++ Series

Arduino IDE Series

Install Arduino IDE

  1. Download the Arduino IDE installation package from Arduino website.
  2. Just click on "JUST DOWNLOAD".
  3. Click to install after downloading.
  4. Note: You will be prompted to install the driver during the installation process, we can click Install.

Install Arduino-Pico Core on Arduino IDE

  1. Open Arduino IDE, click the File on the left corner and choose "Preferences".
  2. Add the following link in the additional development board manager URL, then click OK.
    https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json

    RoArm-M1 Tutorial II05.jpg
    Note: If you already have the ESP8266 board URL, you can separate the URLs with commas like this:

    https://dl.espressif.com/dl/package_esp32_index.json,https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
    
  3. Click on Tools -> Dev Board -> Dev Board Manager -> Search for pico, it shows installed since my computer has already installed it.
    Pico Get Start 05.png
    Pico Get Start 06.png

Upload Demo At the First Time

  1. Press and hold the BOOTSET button on the Pico board, connect the Pico to the USB port of the computer via the Micro USB cable, and release the button when the computer recognizes a removable hard drive (RPI-RP2).

  2. Download the demo, open arduino\PWM\D1-LED path under the D1-LED.ino.
  3. Click Tools -> Port, remember the existing COM, do not need to click this COM (different computers show different COM, remember the existing COM on your computer).
    UGV1 doenload02EN.png
  4. Connect the driver board to the computer with a USB cable, then click Tools -> Ports, select uf2 Board for the first connection, and after the upload is complete, connecting again will result in an additional COM port.
    UGV1 doenload03EN.png
  5. Click Tool -> Dev Board -> Raspberry Pi Pico/RP2040 -> Raspberry Pi Pico.
    Pico Get Start02.png
  6. After setting, click the right arrow to upload.
    • If you encounter problems during the period, you need to reinstall or replace the Arduino IDE version, uninstall the Arduino IDE needs to be uninstalled cleanly, after uninstalling the software you need to manually delete all the contents of the folder C:\Users\[name]\AppData\Local\Arduino15 (you need to show the hidden files in order to see it) and then reinstall.


Open Source Demo


Overview

Introduction

RP2040-LoRa is a LoRa development board using the new generation of SX1262 RF chip, which provides better performance than the SX127X series in power consumption, communication distance, and power efficiency. Adopts LoRa modulation technology to solve the problem in the traditional design solutions which can not balance distance, anti-interference, and power consumption at the same time. Combines with LoRa gateway for connecting Cloud Server such as TTN and ChirpStack for quick verification. Optional for LF/HF frequency band.

Features

  • RP2040 microcontroller chip designed by Raspberry Pi in the United Kingdom.
  • Dual-core Arm Cortex M0+ processor, flexible clock running up to 133 MHz.
  • 264KB of SRAM, and 2MB of onboard Flash memory.
  • Onboard FPC 8PIN connector, adapting USB Type-C port via adapter board.
  • Castellated module allows soldering directly to carrier boards.
  • USB 1.1 with device and host support.
  • Low-power sleep and dormant modes.
  • Drag-and-drop programming using mass storage over USB, up to 20 × multi-function GPIO pins.
  • Supports FSK, GFSK, and LoRa modulation, featuring better anti-blocking and ultra-long distance communication.
  • With -148dBm high reception sensitivity and programmable emit power up to 22dBm.
  • Supports preamble detection, with CRC, up to 256-byte data packet engine.
  • Comes with online resources and manual (example in C).

Specification

VersionRP2040-LoRa-LFRP2040-LoRa-HF
RF ChipSX1262
Frequency BandLF: 410 ~ 450MHzHF: 850 ~ 930MHz
Emit PowerMAX@22dBm (adjustable)
Emit Current107mA@22dBm118mA@22dBm
Receive Current5.3mA@125KHz
Signal ModulationLoRa/(G)FSK
Operation Temperature0 ~ 60℃
Dimensions21.00 × 41.00mm

Hardware Description

Hardware Connection

  • RP2040-LoRa x 1 (included)
  • Type-C USB cable x 1 (not included)

RP2040 & LoRa Pinout
SX1262PicoFunction
SX1262_DIO1GP16SX1262 interrupt output pin or special function pin
SX1262_RSTGP23Reset pin, low active
SX1262_MISOGP24SPI MISO pin, slave device data output
SX1262_MOSIGP15SPI MOSI pin, slave device data input
SX1262_CLKGP14SPI SCK pin, slave device clock data input
SX1262_CSGP13SPI Chip Selection (low active)
SX1262_BUSYGP18SX1262 BUSY Pin
SX1262_ANT_SWGP17Switching between transmit and receive pins, open the transmission switch with a low level

Pinout Definition

  • The Raspberry Pi Pico uses the SPI bus to read and write the 36 registers of the SX1262 to complete LoRa wireless data transmission. The SPI bus frequency should be less than 18MHz. For specific SPI Timing Requires, see Chapter 8 Digital Interface and Control of the datasheet.

  • The SPI bus writing a command to the LoRa chip will trigger the switching of the internal state machine mode. It should be noted that the low level of the BUSY pin indicates that the internal idle is allowed to receive commands, and the high level indicates that the internal occupied cannot accept the SPI command. The SPI bus needs to wait for the BUSY pin Pull low again to continue reading and writing operations, TswMode is up to 3.5ms.



  • SX1262 is a half-duplex LoRa RF chip, SX1262_ANT_SW is a transceiver switching pin, connected to GPIO17 of RP2040, when SX1262 is in transmitting state, GPIO17 should be kept low, and other states should be kept high.

Dimensions


LoRa & LoRaWAN

What is LoRa ?

Semtech's LoRa is a long-distance, low-power wireless platform for the Internet of Things (IoT), which generally refers to radio frequency chips using LoRa technology. The main features are as follows:

  • The spread spectrum modulation technology adopted by LoRa (abbreviation of long-range) is derived from Chirp Spread Spectrum (CSS) technology, which is one of the long-distance wireless transmission technology and LPWAN communication technology. Spread spectrum technology uses bandwidth for sensitivity technology, Wi-Fi, ZigBee, etc. all use spread spectrum technology, but the characteristic of LoRa modulation is that it is close to the limit of Shannon's theorem, and the sensitivity can be improved with maximum efficiency. Compared with traditional FSK technology, at the same communication rate, LoRa is more sensitive than FSK by 8 ~12dBm. At present, LoRa mainly operates in the ISM frequency band of Sub-GHz.
  • LoRa technology integrates technologies such as digital spread spectrum, digital signal processing, and forward error correction coding, which greatly improves the performance of long-distance communication. LoRa's link budget is better than any other standardized communication technology. The main factors that determine the distance in a given environment.
  • LoRa RF chips mainly include SX127X series, SX126X series, SX130X series, of which SX127X, SX126X series are used for LoRa nodes, and SX130X is used for LoRa gateways. For details, please refer to Semtech's product list.

What is LoRaWAN ?

  • LoRaWAN is an open protocol for low-power wide-area networks built on LoRa radio modulation technology. Designed to wirelessly connect battery-powered "things" to the Internet in regional, national, or global networks, and target critical Internet of Things (IoT) requirements such as two-way directional communication, end-to-end security, mobility, and localized services. The node wirelessly connects to the Internet with network access authentication, which is equivalent to establishing an encrypted communication channel between the node and the server. The LoRaWAN protocol level is shown in the figure below.
    • The Class A/B/C node devices in the MAC layer cover all the application scenarios of the Internet of Things. The difference among them is that the time slots for nodes to send and receive are different.
    • EU868 and AS430 in the Modulation layer show that frequency band parameters are different in different countries. Please click the reference link for regional parameters.



  • To achieve LoRaWAN network coverage in cities or other areas, it needs to be composed of four parts: node (LoRa node radio frequency chip), gateway (or base station, LoRa gateway radio frequency chip), server, and cloud, as shown in the following figure.
    • The DEVICE (node device) needs to initiate a network access request packet to the GATEWAY (gateway) and then to the server. After the authentication is passed, it can send and receive application data with the server normally.
    • GATEWAY (gateway) can communicate with the server through a wired network, 3/4/5G wireless network
    • The main operators on the server side are TTN, etc. For building cloud services by yourself, please refer to lorawan-stackchirpstack

1350px-SX1268-LoRa-HAT-021.png


  • There are two methods for Raspberry Pico and Pico-LoRa-SX1262 to connect to the network via LoRaWAN: OTAA (Over-The-Air-Activation) and ABP (Activation By Personalization). Here we use OTAA, as shown below. Also, you can refer to link 1link 2 and source code.
  • Step 1: Please send the "Join-Request" message to the network to be added, and note that the adding process is always initiated by the end device. The join-Request message can be transmitted at any rate and in one of the region-specific join channels. For example: in Europe, the end device can send the join-Request message at 868.10 MHz, 868.30MHz, or 838.50MHz. Also, the message can be sent to the network server by one or more gateway. In addition, you need to pay attention to choosing the applicable frequency band according to the local radio management regulations. You can refer to link and LoRa Alliance for the frequency distribution table. The Join-Request message is combined by the following fields, AppEUI, and DevEUI are generated by the server end.
    • AppEUI: A 64-bit globally unique application identifier in the IEEE EUI64 address space that uniquely identifies an entity capable of processing Join-Request frames.
    • DevEUI: A 64-bit globally unique device identifier that uniquely identifies an end device in the IEEE EUI64 address space.
    • DevNonce: A unique random 2-byte value generated by the end device. The web server uses each end device's DevNonce to keep track of their join requests. If the end device sends a join request with the previously used DevNonce (this case is called a replay attack), the network server will reject the join request and will not allow the end device to register with the network.
  • Step 2: The web server handles the Join-Request-Message. If the end device is allowed to join the network, the web server will generate two session keys (NwkSKey and AppSKey) and the Join-accept message. The Join-accept message itself is then encrypted using AppKey. The web server uses AES decryption operation in ECB mode to encrypt Join-accept messages.
  • Step 3: The network server sends the encrypted join to accept the message back to the end device as a normal downlink.
  • Step 4: The end device uses AES to decrypt Join-Accept. And uses AppKey and AppNonce to generate two session keys NwkSKey and AppSKey for subsequent communication with the Networking server. The Network Server also saves kSKey, Join server distributes AppSKey to Application Server.



  • The DevEUI and AppEUI parameters used as terminal devices to access the Internet need to be registered and generated by the server. The specific process is as follows:
    • Register an account in TTS and log in. Create an Application.


    • Add an End Device
Pico-LoRa-SX1262-868M 007.jpg
    • Configure the End Device as in the picture. Please save the DevEUI and the AppKey for further use.


Application

LoRa devices and networks such as LoRaWAN enable smart IoT applications to help solve the planet's formidable challenges in energy management, natural resource reduction, pollution control, infrastructure efficiency, disaster prevention, and more. Semtech's LoRa devices have achieved hundreds of successful use cases in smart cities, homes and buildings, communities, metrology, supply chain, and logistics, agriculture, and more. LoRa networks have covered hundreds of millions of devices in more than 100 countries and are committed to a smarter planet.

Environment Building

  • We use VScode(Cmake) to compile the environment on Windows 10 in this tutorial, and you can click to download the related IDE, install, and then open.
  • Please refer to Pico Documentation and one-click installer for VScode(Cmake) compilation environment and its installation.

Rp2040-lora-005.JPG



  • After installing the RP2040 development environment with one click, open the terminal in the Windows Start menu directory, enter "code" to launch the VSCode compilation environment, and use VSCode to open the [sample demo] folder.
  • Click the gear-shaped "Build" button in the toolbar below, pop up the compilation tool options tab, and select the GCC 10.3.1 arm-none-eabi compilation toolchain to compile the code.

Demo Analysis

  • In RP2040-LoRa-code, "otaa_temperature_led" is for connecting the TTN cloud platform and transmitting the message, which requires a LoRaWAN gateway. Before compiling, you need to input the DevEUI and AppKey values that users apply in the cloud platform in the "config.h" text.
    • If the environment settings are correct, click the Build button of VScode to wait for the compilation to end, download the compiled file to the RaspberryPi Pico that enters the Boot mode, and open the serial port to view the log information.





  • The ping-pong example requires two sets of RP2040-LoRa-HF-Kit for testing communication. After downloading the example, both modules will continuously send the "Ping" string message. Upon receiving the "Ping" message, one of them will reply with the "Pong" string.


    • Radio.SetTxConfig() function is used to set the LoRa mode, including but not limited to bandwidth, spreading factor, coding rate, the length of the leading code, and other information, Radio.SetRxConfig() is used to set the information of the receiving mode, the built-in LoRa chip transmitting and receiving is a half-duplex state, at the same time can only be in sent or received mode.
    Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,
                                   LORA_SPREADING_FACTOR, LORA_CODINGRATE,
                                   LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
                                   true, 0, 0, LORA_IQ_INVERSION_ON, 3000 );

    Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR,
                                   LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH,
                                   LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON,
                                   0, true, 0, 0, LORA_IQ_INVERSION_ON, true );

    Radio.SetMaxPayloadLength( MODEM_LORA, BUFFER_SIZE );
    • main() function uses the variable to label LoRa as Master by default, send "Ping", it enters the RX mode, waiting for "Pong" response. If the RX mode is timeout, you can send "Ping" again. If it receives a "Ping", it can be labeled as "Pong". Then, these two modules continuously transmit and receive like "Pingpong", and the onboard LED blinks when receiving the message.
while( 1 )
{
    switch( State )
    {
        case RX:
        case TX:
        case RX_TIMEOUT:
        case RX_ERROR:
        case TX_TIMEOUT:
        case LOWPOWER:
        default:
    }
    BoardLowPowerHandler( );
    // Process Radio IRQ
    if( Radio.IrqProcess != NULL )
    {
        Radio.IrqProcess( );
    }

}

Other Messages

  1. With the pico-lorawan foundation, this demo also includes support for the RP2040-LoRa module based on the Semtech SX1262.
  2. For LoRaWAN protocol, you can refer to this link.
  3. If you want to establish a cloud server by yourself, you can refer to lorawan-stack and chrpstack.