Elecrow nRFLR1121 Wireless Transceiver Module-Integrates Nordic nRF52840 and Semtech SX1121 Point-to-Point Communication¶
In this lesson, we will focus on how to use the nRFLR1121 to transmit data.
This product boasts high performance with a maximum transmit power of +20dBm, supporting a transmission rate of 1.91~62.5kbps, a sensitivity of -141dbm SF12/BW=125kHz, and a 166db link budget. It features ultra-low power consumption, with a sleep current as low as 6uA. It supports the sub-GHz and global 2.4GHz spectrum, as well as the S-band, and enables LoRa point-to-point (P2P) communication. The wireless connection supports the 850~930MHz global LoRa&LoRaWAN ISM frequency and is compatible with low-power Bluetooth, Bluetooth mesh network, NFC, Thread, and Zigbee. With built-in AT command firmware, it supports customized product development using the SDK, and the AT command set can be easily accessed via the UART interface. For long-distance communication needs, it can reach up to 10km. Additionally, it comes with rich peripherals, exposing various GPIO interfaces such as UART, I2C, and ADC, offering great flexibility. Despite its powerful features, it has a compact form factor, measuring only 20x20x3.5 mm and has obtained FCC, CE, and RoHS certifications.
As shown in the figure below, we are using the nRFLR1121 module with each interface connected to a sensor. This setup allows us to collect data from each sensor and transmit the data to another nRFLR1121 module using LoRa technology. Finally, the received data can be viewed through the serial port.
Next, let’s explore this together.
First, open the code files.
The GitHub download link for the code of this lesson is https://github.com/Elecrow-RD/Elecrow-nRFLR1121-Wireless-Transceiver-Module . Please find the corresponding code in the "example" folder within the link.
The nRFLR1121 _Sender file is used to collect sensor data and transmit it.
The nRFLR1121 _Receiver file is used to receive the data.
Let's first introduce the code structure of the sender.
We'll go through it module by module:
Bulb: Connected to the nRFLR1121 module's GPIO_D interface, which corresponds to pin 26
Button: Connected to the nRFLR1121 module's GPIO_D interface, which corresponds to pin 12
DHT20 Temperature and Humidity Sensor: Connected to the nRFLR1121 module's I2C interface, which corresponds to pins 13 and 14
Accelerometer: Also connected to the nRFLR1121 module's I2C interface, pins 13 and 14
u8g2 Display: Connected to the nRFLR1121 module's I2C interface, pins 6 and 7
IR Receiver: Connected to the nRFLR1121 module's UART interface, which corresponds to pins 22 and 24
GPS Module: Connected to the nRFLR1121 module's GPIO_A interface, which corresponds to pins 29 and 28
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.
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).
And then, set the logic for turning the bulb on and off.
DHT20 Temperature and Humidity Sensor¶
Initialize the libraries and variables to be used first.
Then initialize the temperature and humidity sensor in setup.
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 nRFLR1121 module.
Next, in the loop function, retrieve the temperature and humidity values and store them in the temperature and humidity variables within the structure.
After retrieving the temperature and humidity values, you can print them to the serial monitor to check the values.
Then, combine them into the payload variable for easier transmission together.
Here, LoRa technology is used to transmit the data.
Accelerometer¶
First, according to the technical manual of the LSM6DS3 accelerometer, explain and define its relevant registers.
Since both the accelerometer and the temperature and humidity sensor use the I2C protocol, their pins have already been initialized.
Then, in the loop function, repeatedly retrieve the acceleration values in all three directions.
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.
Finally, transmit the data to another nRFLR1121 module.
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.
And in the setup function, initialize the display.
Then, in the loop function, set up the display and continuously update the displayed values.
IR Receiver¶
Initialize the pin 24, which is connected to the infrared sensor.
Then, initialize the infrared receiver sensor in the setup function.
In the loop function, continuously process and receive the infrared signals sent by the remote control.
You can specifically map the key values represented by the infrared remote control buttons.
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.
GPS positioning module¶
Since the GPS module is connected to the GPIO_A interface, we initialize the UART interface pins 28 and 29.
Then, initialize the baud rate required for the serial communication.
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.
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.
LoRa module¶
First, initialize the pins for the LoRa module.
You can open the schematic diagram we provided.
In our schematic diagram, you can identify the pins required for the LoRa module based on the nRFLR1121 chip's pins.
In the setup function, configure the relevant settings for the LoRa module.
Finally, in the loop function, repeatedly send the data collected from the sensors.
The overall data sent by the transmitter is shown in the diagram below.
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.
Next, the most important thing is that the frequency band must match the one used by the transmitter.
Next, the data sent by the transmitter needs to be parsed.
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.
You can compare the sent message with the received information.
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:
-
Since the nRFLR1121 uses the nrf52840 as the main control chip, you need to install the nrf52 development board.
-
Use the library files we provided
-
Pay attention to the configuration during the flashing process.