Skip to content

5. Examples

Yoshio Garcia edited this page Dec 22, 2023 · 3 revisions

The LoRa and LoRaWAN technologies are supported by the Catwan Arduino LoRa Shield. We will look at how each of these technologies may be used for different exercises and applications in the section that follows.

For the following examples, we will need an Arduino UNO board (in this case, we will use an Arduino UNO R4 WiFi) and the CatWAN Arduino LoRa Shield.

Imagen 0
Arduino UNO R4 Wi-Fi.
Imagen 1
CatWAN Arduino LoRa Shield V1.0

Remember that to use this module you need to have the "LoRa library by Sandeep Mistry" installed. If you have not installed it yet, check the section: Install the Library.

Using LoRa

The LoRa technology, on its own, is ideal for applications that require long-range communication and low energy consumption. Its main uses include sending and receiving information over considerable distances, as well as remote control.

In the LoRa examples, we will show seamless communication between two boards using LoRa technology. To achieve this we will need two boards that have LoRa technology.

In this case, we will use the Arduino UNO R3 together with the CatWAN Arduino LoRa Shield and another of our boards, the BastWAN, which is compatible with LoRa technology. The BastWAN is available in our store. This combination of hardware illustrates the versatility and compatibility of different products.

Example Device-to-device communication

For this first example, we will use the basic examples from the repository, you can find this in the LoRa Examples folder.

If you are using two Arduino UNO boards and two CatWAN Arduino LoRa Shields, you will only have to upload the codes from the LoRa Examples folder.


Using two CatWAN Arduino LoRa Shield + Arduino UNO R4 WiFi

In case you use an Arduino UNO + CatWAN Arduino LoRa Shield and another different board with LoRa. The code to upload to your Arduino UNO must be one of those found in the LoRa Examples folder according to its role (Sender or Receiver) and the code to upload to your other board will depend on the module and library used.

In this case, we will use a BastWAN as a sender device and a CatWAN Arduino LoRa Shield + Arduino R4 WiFi as a receiver device.


Using a CatWAN Arduino LoRa Shield + Arduino UNO R4 WiFi and a BastWAN

So, we will upload the "LoRaReceiver example code" to our Arduino R4 WiFi.

As mentioned above, when using a different board, it is necessary to use the example for the board to use, in our case, we will upload the BastWAN Sender example code to our BastWAN.

After this, our boards should start communicating and now we will be able to see the values we receive through the serial port:


Serial Output

Using LoRaWAN

For the following examples, we will use only a CatWAN Arduino LoRa Shield and an Arduino UNO R4 WiFi


Using a CatWAN Arduino LoRa Shield + Arduino UNO R4 WiFi

LoRaWAN with ABP Class C using the Beelan LoRaWAN library

For this example, we will use the "class-C-ABP" example from the Beelan LoRaWAN library, which you can find by going to Arduino IDE->Examples->Beelan LoRaWAN->class-C-ABP.


Finding the class-C-ABP example

Before continuing, in order to carry it out you need to have an end device configured. In our case, we use TTN for this application and configure an ABP Class C device.

Once you configured your end device, you should look for:

  • DevAddr
  • NwkSKey
  • AppSKey

These are essential data to configure the device and then replace the values in the example code.


Configuring our device

As Beelan is a general-purpose library, we must modify the pins so that the Arduino UNO R4 WiFi communicates correctly with the CatWAN Arduino LoRa Shield. For this, you have to look for the section of code where it is declared "const sRFM_pins RFM_pins".


Setting the data pins

Now, when we open the serial port we can see that we are sending data.


Serial output

To verify that your board is configured correctly and that it now transmits through LoRaWAN, we will check in the LoRaWAN device manager (in our case TTN) that the information is received correctly.


Data Received