Skip to content

LR1262 Point-to-Point Communication

In this lesson, we will focus on how to use the LR1262 to transmit data.

The LR1262 is a low-cost, ultra-low-power, and ultra-compact LoRa® RF module, based on the high-performance Semtech SX1262 LoRa® wireless communication IC. It supports LoRa and LoRaWAN frequencies ranging from 868 MHz to 915 MHz and primarily utilizes the next-generation LoRa™ modulation technology for ultra-long-range spread spectrum communication.

The LR1262 module is equipped with a high-quality TCXO, ensuring stable operation in industrial environments with extreme temperatures. Designed specifically for wireless sensor networks and other IoT devices, it is particularly suitable for applications requiring battery power, low power consumption, and long-range connectivity. The module features an SPI interface, allowing users to achieve wireless data transmission and reception by connecting it to an MCU via IO.

Its maximum transmission power can reach +22dBm, supporting a transmission rate of 1.76 to 62.5 kbps, and covers the global LoRa & LoRaWAN ISM frequency range of 850 to 930 MHz. Equipped with a high-quality TCXO crystal oscillator, it is resistant to extreme temperatures and runs stably with a sleep current as low as 1.62μA, making it especially suitable for smart home applications, wireless meter reading, scientific research, medical use, and medium-to-long distance wireless communication devices.

img

As shown in the figure below, we are using the LR1262 module with each interface connected to a sensor. This setup allows us to collect data from each sensor and transmit the data to another LR1262 module using LoRa technology. Finally, the received data can be viewed through the serial port.

img

img

Next, let’s explore this together.

First, open the code files. The LR1262_Sender file is used to collect sensor data and transmit it. The LR1262_Receiver file is used to receive the data.

Code Link:

https://github.com/Elecrow-RD/LR1262-Long-Range-LoRa-Wireless-Transceiver-Module

img

Let's first introduce the code structure of the sender. We'll go through it module by module:

Bulb: Connected to the LR1262 module's GPIO_D interface, which corresponds to pin 12

Button: Connected to the LR1262 module's GPIO_D interface, which corresponds to pin 14

DHT20 Temperature and Humidity Sensor: Connected to the LR1262 module's I2C interface, which corresponds to pins 40 and 41

Accelerometer: Also connected to the LR1262 module's I2C interface, pins 40 and 41

u8g2 Display: Connected to the LR1262 module's I2C interface, pins 38 and 39

IR Receiver: Connected to the LR1262 module's UART interface, which corresponds to pins 19 and 20

GPS Module: Connected to the LR1262 module's GPIO_A interface, which corresponds to pins 15 and 16

img

Next, let’s first talk about the implementation of the bulb and the button.

Light bulbs and buttons


The main function is to turn the bulb on or off by pressing the button.

First, define the pins for the two interfaces.

img

Then, in the setup function, configure the pins as input or output and set the interrupt condition. Interrupt configuration: connect the button pin (14) to an interrupt, assign the interrupt service routine to toggle the LED, and set the trigger condition to rising edge (i.e., when the button is pressed).

img

And then, set the logic for turning the bulb on and off.

img

DHT20 Temperature and Humidity Sensor


Initialize the libraries and variables to be used first.

img

Then initialize the temperature and humidity sensor in setup.

img

The structure defined here contains the values for temperature, humidity, and acceleration in three directions. The purpose is to later transmit all this data together to another LR1262 module.

img

Next, in the loop function, retrieve the temperature and humidity values and store them in the temperature and humidity variables within the structure.

img

After retrieving the temperature and humidity values, you can print them to the serial monitor to check the values.

img

Then, combine them into the payload variable for easier transmission together.

img

Here, LoRa technology is used to transmit the data.

img

Accelerometer


First, according to the technical manual of the LSM6DS3 accelerometer, explain and define its relevant registers.

img

Since both the accelerometer and the temperature and humidity sensor use the I2C protocol, their pins have already been initialized.

img

Then, in the loop function, repeatedly retrieve the acceleration values in all three directions.

img

The writeRegister and readRegister functions are custom functions we’ve written. (You can refer to the code for more details, as the comments provided are quite detailed.)

writeRegister: Writes data to a register

readRegister: Reads data from a register

After obtaining the acceleration data, combine it into the payload variable for easier transmission together.

img

Finally, transmit the data to another LR1262 module.

img

U8g2 display screen


In this experiment, we also added a display to show the temperature and humidity values. At the beginning of the code, the display configuration is initialized. Although the display also uses the I2C interface, here we are using software-based I2C.

img

And in the setup function, initialize the display.

img

Then, in the loop function, set up the display and continuously update the displayed values.

img

IR Receiver


Initialize the pin 19, which is connected to the infrared sensor.

img

Then, initialize the infrared receiver sensor in the setup function.

img

In the loop function, continuously process and receive the infrared signals sent by the remote control.

img

You can specifically map the key values represented by the infrared remote control buttons.

img

Here, I pressed the key value "2" on the infrared remote control. After receiving the infrared signal, the corresponding information will be displayed in the serial monitor as shown below.

img

GPS positioning module


Since the GPS module is connected to the GPIO_A interface, we initialize the UART interface pins 15 and 16.

img

Then, initialize the baud rate required for the serial communication.

img

In this while loop, as long as there is available data on the software serial, the loop body will continuously execute. The SoftSerial.read() function reads a byte of data from the software serial and stores it in the incomingByte variable. Then, the received byte is printed to the hardware serial (usually connected to a computer for debugging and data monitoring) using Serial.print(incomingByte). Next, the received byte is stored in the buffer array, and the count variable is incremented to track the number of bytes stored. When count reaches 256, the loop exits to prevent an array overflow.

img

As you can see here, we haven't processed the received GPS signals. If you're interested, you can explore it further to obtain the desired latitude and longitude information.

img

LoRa module


img

First, initialize the pins for the LoRa module.

img

You can open the schematic diagram we provided.

img

img

In our schematic diagram, you can identify the pins required for the LoRa module based on the ESP32-S3 chip's pins.

In the setup function, configure the relevant settings for the LoRa module.

img

img

Finally, in the loop function, repeatedly send the data collected from the sensors.

img

The overall data sent by the transmitter is shown in the diagram below.

img

This is the overall structure of the transmitter. Next, let's take a look at the code structure for the receiver.

Receiving end


The receiver also starts by initializing the pins for the LoRa module.

img

Next, the most important thing is that the frequency band must match the one used by the transmitter.

img

img

Next, the data sent by the transmitter needs to be parsed.

img

The parseSensorData function is a parsing function I wrote. I won't go into detail here, but its purpose is to parse the data that was packaged and sent over.

img

You can compare the sent message with the received information.

img

Perfect! The LoRa module successfully transmitted the data!

This concludes the explanation of the transmitter and receiver code. Lastly, here are some points to keep in mind during actual operation:

  1. Since the LR1262 uses the ESP32-S3 as the main control chip, you need to install the ESP32 development board.

    img

  2. Use the library files we provided

    (Reference path).

    img

  3. Pay attention to the configuration during the flashing process.

    img