Getting started
ESP32 based PLC with LoRa module from Industrial Shields incorporates the RN2483 module. In a previous post we saw how to interact with it, writing directly to the Serial Port to configure the module, send and receive messages.
As this procedure is slow and not optimal, Industrial Shields developed a new library for the ESP32 based PLCs which include RN2483 module. The development of this library has focused on the integration of the already existing Radio Head libraries, using the same functions and adapting the payload messages to simulate the format.
This way, the ESP32 PLC or the ESP32 PLC 14 can communicate with any other Radio Head module with ease, without the need of externally prepare the packet which will be sent, or perform any other strategies that slow down the sending or receiving process. In addition, the communication between the Arduino based PLCs such as the M-Duino LoRa or the Ardbox LoRa is possible.
Check out the previous post for a basic understanding about the module, and let's jump into the library.
Default configuration parameters
The RN2483 LoRa module is configured with the following parameters to match the existing default configuration for the rest of the Radio Head modules:
- Coding Rate: 4/5
- Band Width: 125 kHz
- Preamble Length: 8
- Spreading Factor: 12
- TX Power: 13
- Frequency: 868 MHz
- Sync Word: 0x12
Each of this values can be modified after starting the module.
First steps with the RN2483 library
The steps to set up the module are very simple:
- First of all, include the library to the Arduino IDE sketch:
- Initialize the LoRa object with the Serial Port:
For ESP32 PLC:
For ESP32 PLC 14:
- Start the Serial Port at 57600 baud rate:
For ESP32 PLC 14:
- Reset the LoRa module:
For ESP32 PLC 14:
- Finally, start the LoRa module:
You can find an example code for your ESP32 based PLC in File -> Examples ->
Interaction with the module
After starting the module, we can start sending and receiving LoRa packets from another module. The send function should have the following form:
The size of the LoRa packet should not exceed 255 bytes, otherwise the send function will fail. The send can take up to almost 2 seconds, so keep in mind that during that time, the module is not able to receive any data from any LoRa module at all.
The receive function should be called with:
"LoRa.available()" must be called before attempting to read a LoRa packet to ensure that a valid message was received, otherwise the data read from "LoRa.recv(buf, len)" is unpredictable. The message stored in buf has the following format:
- If the sender send "A", in the buf array there will be {"4", "1"}, with len = 2. This corresponds to the ASCII equivalent from "A" to decimal 41.
To print just the buffer, use the "LoRa.printBuffer(buf, len)" function. This will print the contents of the received message in a readable format plus a new line character.
RN2483 LoRa library for ESP32 based PLCs