LoRa module on Raspberry PI

First steps with the LoRa module on Raspberry Pi
September 30, 2024 by
Boot & Work Corp. S.L., Arnau Tena

Requirements and setup

Before we try anything with the module, we must make sure that the PLC fulfills certain requirements.

First of all, install Industrial Shield's librpiplc library following the instructions from the repository. When cloning the repository, you have to replace <tagname> with the desired librpiplc verion. For this blog, we installed v3.0.0.

LIBRPIPLC Library

Next, we must make sure that the config.txt file is set up correctly. To do this, first open /boot/config.txt with your preferred text editor, in this case we use nano:

sudo nano /boot/config.txt

Use your arrow keys to reach the bottom of the file, and make sure you have these lines set up like this:

[all]
dtparam=spi=on
gpio=8=pd
dtoverlay=spi0-1cs,cs0_pin=7
dtoverlay=w5500,cs=0,int_pin=6
dtparam=i2c_arm=on
dtoverlay=i2c-rtc,ds3231
dtoverlay=sc16is752-spi1-rpiplc-v4,xtal=14745600
enable_uart=1

You can now close the text editor. If you opened the file using nano, you can close it by pressing Ctrl+X. If nano asks you for confirmation before closing, type Y to confirm and then press Enter to keep the same filename.

 Testing

With everything configured correctly, we can begin testing the module to ensure that everything is working correctly.

Depending on where the module was installed, the commands to use will be a bit different. The module can either be in slot 1 or slot 2, with slot 1 being just besides the ethernet port. Follow the testing instructions according to where the module is installed:

Testing the LoRa module

Enable the LoRa module by setting the reset pin to high.  You'll also need the model and version of your RPIPLC to replace [RPIPLC_Version] and [RPIPLC_Model].

RPIPLC Models and Versions

sudo ~/test/[RPIPLC_Version]/[RPIPLC_Model]/set-digital-output EXP1_RST 1

With the reset pin set to high, we can now test the LoRa module itself. We will need two terminals for this, one to send data to the module and another one to recieve its response.

In the first terminal, open the port with a baudrate of 57600, which is the default baudrate of the module. In case of any errors, you can try to use a different baudrate.

(it's important to incluede raw -echo, or you could encounter issues)

stty 57600 -F /dev/ttySC0 raw -echo

Now, leave the port listening with cat:

cat /dev/ttySC0

Go to the second terminal. We will ask the module for its version to confirm that we can communicate with it:

echo -e "sys get ver\r" > /dev/ttySC0

If everything went well, you should see something like "RN2483 1.0.5 Oct 31 2018 15:06:52" in the first terminal, which should still be listening for any incoming data. To stop it from listening, you can press Ctrl+C.

Test communication between two LoRa modules

Now you can set up a second RPIPLC with the LoRa module and try to communicate with it. On the second RPIPLC you'll have to repeat the same setup steps we did on the first RPIPLC, and also enable the reset pin and open the port at the same baudrate.

After that, you have to set the frequency that the modules will use to send and recieve messages. If you have the RN2483A LoRa module, you can either use European (868MHz) or Asian (433MHz) frequencies. If instead you have the RN2903 LoRa module, you have to set the frequency to the American one (915MHz). In this case we ue the European one:

echo -e "radio set freq 868000000\r" > /dev/ttySC0

 We prepare one of the RPIPLCs to recieve messages:

echo -e "mac pause\r" > /dev/ttySC0
echo -e "radio rx 0\r" > /dev/ttySC0
cat /dev/ttySC0

And then send the message from the other RPIPLC with:

echo -e "mac pause\r" > /dev/ttySC0
echo -e "radio tx ABC\r" > /dev/ttySC0

Upon succesful communication, you should see something like 'radio_rx 0ABC' in the recieving RPIPLC's terminal.

Useful commands and further documentation

You can send LoRa commands by following this structure:

echo -e "[COMMAND]\r" > /dev/ttySC0

Where [COMMAND] will be the actual LoRa command itself. Here are some useful examples you can use:

  • mac pause: Pause the LoRaWAN stack functionality and allow transceiver
  • radio rx 0: Listen for data.
  • radio tx ABC: Send a message (ABC).
  • radio set freq [FREQUENCY]: Set the frequency of the radio transceiver.

You can also find further documentation on LoRa here:

LoRa Documentation

Testing the LoRa module

Enable the LoRa module by setting the reset pin to high.  You'll also need the model and version of your RPIPLC to replace [RPIPLC_Version] and [RPIPLC_Model]. If you are using a librpiplc version older than v3.0.0, EXP2_RST will instead be named EXP1_RST_2.

RPIPLC Models and Versions

sudo ~/test/[RPIPLC_Version]/[RPIPLC_Model]/set-digital-output EXP2_RST 1

With the reset pin set to high, we can now test the LoRa module itself. We will need two terminals for this, one to send data to the module and another one to recieve its response.

In the first terminal, open the port with a baudrate of 57600, which is the default baudrate of the module. In case of any errors, you can try to use a different baudrate.

(it's important to incluede raw -echo, or you could encounter issues)

stty 57600 -F /dev/ttySC1 raw -echo

Now, leave the port listening with cat:

cat /dev/ttySC1

Go to the second terminal. We will ask the module for its version to confirm that we can communicate with it:

echo -e "sys get ver\r" > /dev/ttySC1

If everything went well, you should see something like "RN2483 1.0.5 Oct 31 2018 15:06:52" in the first terminal, which should still be listening for any incoming data. To stop it from listening, you can press Ctrl+C.

Test communication between two LoRa modules

Now you can set up a second RPIPLC with the LoRa module and try to communicate with it. On the second RPIPLC you'll have to repeat the same setup steps we did on the first RPIPLC, and also enable the reset pin and open the port at the same baudrate.

After that, you have to set the frequency that the modules will use to send and recieve messages. If you have the RN2483A LoRa module, you can either use European (868MHz) or Asian (433MHz) frequencies. If instead you have the RN2903 LoRa module, you have to set the frequency to the American one (915MHz). In this case we ue the European one:

echo -e "radio set freq 868000000\r" > /dev/ttySC1

 We prepare one of the RPIPLCs to recieve messages:

echo -e "mac pause\r" > /dev/ttySC1
echo -e "radio rx 0\r" > /dev/ttySC1

And then send the message from the other RPIPLC with:

echo -e "mac pause\r" > /dev/ttySC1
echo -e "radio tx ABC\r" > /dev/ttySC1

Upon succesful communication, you should see something like 'radio_rx 0ABC' in the recieving RPIPLC's terminal.

Useful commands and further documentation

You can send LoRa commands by following this structure:

echo -e "[COMMAND]\r" > /dev/ttySC1

Where [COMMAND] will be the actual LoRa command itself. Here are some useful examples you can use:

  • mac pause: Pause the LoRaWAN stack functionality and allow transceiver
  • radio rx 0: Listen for data.
  • radio tx ABC: Send a message (ABC).
  • radio set freq [FREQUENCY]: Set the frequency of the radio transceiver.

You can also find further documentation on LoRa here:

LoRa Documentation


​Search in our Blog

Boot & Work Corp. S.L., Arnau Tena September 30, 2024
Share this post

Looking for your ideal Programmable Logic Controller?

Take a look at this product comparison with other industrial controllers Arduino-based. 

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.


Industrial PLC comparison >>>