Utilizing Reyax RYLR890 LoRa Modules

Good evening friends,

I am working on a project that will allow the user to control a 16 channel relay board with a remote transmitter at a distance exceeding 1 km. I decided to utilize LoRa technology to accomplish this. After doing research on the internet I purchased and connected the following parts for the transmitter and receiver:

Transmitter:

Receiver:

I have also drawn a crude rendition of how I have them hooked up and added it as an attachment.

Here is the code that I have running as the transmitter:

#include <IRremote.h>


const int RECV_PIN = A7;

IRrecv irrecv(RECV_PIN);

decode_results results;


void setup() {

 // put your setup code here, to run once:

 Serial.begin(115200);

 //removed following code because when nano is connected it sends serial data to the usb not the lora module

 delay(50);

 //Serial.print("AT+IPR=115200\r\n");

 //delay(50);

 //Serial.print("AT+ADDRESS=2\r\n");

 //delay(50);

 //Serial.print("AT+NETWORKID=5\r\n");

 //delay(50);

 //Serial.print("AT+MODE=0\r\n");

 //delay(50);

 //Serial.print("AT+BAND=915000000\r\n");

 //delay(50);

 //Serial.print("AT+PARAMETER=10,7,1,7\r\n");

 //delay(50);

 pinMode(RECV_PIN,INPUT);

 delay(50);

 irrecv.enableIRIn();

 delay(50);

 irrecv.blink13(true);

 delay(50);

}


void loop(){

   if (irrecv.decode(&results)){


       switch(results.value){

         case 0XFF30CF: //Keypad button "1"

         Serial1.println("AT+SEND=1,6,R1");

         delay(500);

         }

       switch(results.value){

         case 0XFF18E7: //Keypad button "2"

         Serial1.println("AT+SEND=1,6,R2");

         delay(500);

         }

       switch(results.value){

         case 0XFF7A85: //Keypad button "3"

         Serial1.println("AT+SEND=1,6,R3");

         delay(500);

         }

       switch(results.value){

         case 0XFF10EF: //Keypad button "4"

         Serial1.println("AT+SEND=1,6,R4");

         delay(500);

         }

       switch(results.value){

         case 0XFF38C7: //Keypad button "5"

         Serial1.println("AT+SEND=1,6,R5");

         delay(500);

         }

       switch(results.value){

         case 0XFF5AA5: //Keypad button "6"

         Serial1.println("AT+SEND=1,6,R6");

         delay(500);

         }

       switch(results.value){

         case 0XFF42BD: //Keypad button "7"

         Serial1.println("AT+SEND=1,6,R7");

         delay(500);

         }

       switch(results.value){

         case 0XFF4AB5: //Keypad button "8"

         Serial1.println("AT+SEND=1,6,R8");

         delay(500);

         }

       switch(results.value){

         case 0XFF52AD: //Keypad button "9"

         Serial1.println("AT+SEND=1,6,R9");

         delay(500);

         }

       switch(results.value){

         case 0XFF6897: //Keypad button "0"

         Serial1.println("AT+SEND=1,6,R0");

         delay(500);

         }

       switch(results.value){

         case 0XFFE21D: //Keypad button "CH+"

         Serial1.println("AT+SEND=1,6,CH+");

         delay(500);

         }

       switch(results.value){

         case 0XFFA25D: //Keypad button "CH-"

         Serial1.println("AT+SEND=1,6,CH-");

         delay(500);

         }


       irrecv.resume();

   }

}

I have been adjusting the code over the past couple of days in order to help isolate different parts of the project to determine what was operating properly. That is why some of the setup code was turned into comments. I decided to separately program the Lora module because I was not sure if the Arduino Nano was sending the serial info through the USB when it was connected to the computer instead of the TX1 and RX0 pins. If someone could inform me of whether or not this is true that would be helpful.

Here is the code that the receiver is operating:

//Define PIN constant

const int relay_1 = 22;

const int relay_2 = 23;

const int relay_3 = 24;


int Current_relay = 0; //Define integer to remember the current active relay


int toggleState_1 = 0; //Define integers to remember the toggle state for switchs 1-3

int toggleState_2 = 0;

int toggleState_3 = 0;


String incomingString;


void setup()

{  


  Serial1.begin(115200);

  delay(50);

  Serial.begin(115200);

  delay(50);

  Serial1.print("AT+IPR=115200\r\n");

  delay(50);

  Serial1.print("AT+ADDRESS=1\r\n");

  delay(50);

  Serial1.print("AT+NETWORKID=5\r\n");

  delay(50);

  Serial1.print("AT+MODE=0\r\n");

  delay(50);

  Serial1.print("AT+BAND=915000000\r\n");

  delay(50);

  Serial1.print("AT+PARAMETER=10,7,1,7\r\n");

  delay(50);


  pinMode(relay_1, OUTPUT);

  pinMode(relay_2, OUTPUT);

  pinMode(relay_3, OUTPUT);


}


void relayOnOff(int relay){


   switch(relay){

     case 1:

            if(toggleState_1 == 0){

             digitalWrite(relay_1, HIGH); // turn on relay 1

             toggleState_1 = 1;

             Current_relay = 1;

             }

            else{

             digitalWrite(relay_1, LOW); // turn off relay 1

             toggleState_1 = 0;

             Current_relay = 0;

             }

            delay(100);

     break;

     case 2:

            if(toggleState_2 == 0){

             digitalWrite(relay_2, HIGH); // turn on relay 2

             toggleState_2 = 1;

             Current_relay = 2;

             }

            else{

             digitalWrite(relay_2, LOW); // turn off relay 2

             toggleState_2 = 0;

             Current_relay = 0;

             }

            delay(100);

     break;

     case 3:

            if(toggleState_3 == 0){

             digitalWrite(relay_3, HIGH); // turn on relay 3

             toggleState_3 = 1;

             Current_relay = 3;

             }else{

             digitalWrite(relay_3, LOW); // turn off relay 3

             toggleState_3 = 0;

             Current_relay = 0;

             }

            delay(100);

     break;            

     default : break;      

     }

 

}


void loop() {


if(Serial1.available()) {

   incomingString = Serial1.readString();

   if(incomingString.indexOf("R1") >0) {

     relayOnOff(1);

     Serial.println("111111");

   }

   else if(incomingString.indexOf("R2") >0) {

     relayOnOff(2);

     Serial.println("222222222");

   }

   else if(incomingString.indexOf("R3") >0) {

     relayOnOff(3);

     Serial.print("3333333");

   }

   else if(incomingString.indexOf("CH+") >0) {

     relayOnOff(Current_relay);

     Current_relay=Current_relay+1;

     relayOnOff(Current_relay);

   }

   else if(incomingString.indexOf("CH-") >0) {

     relayOnOff(Current_relay);

     relayOnOff(Current_relay-1);

   }

  delay(100);

}

}

I am a beginner to Arduino and this is my first project. I have been troubleshooting the different parts of the project and I believe the issue is with the communication between the Lora modules or the Arduinos with the Lora modules. I am able to get the Nano to print the associated AT commands to the serial monitor when I connect it to the computer and use the IR remote. I am able to send AT commands to the Mega to control the relay board through the serial monitor and all of the power supplies work well.

All of this to say that I am hoping someone with more experience with me can look through my code and hardware to see if I am making a stupid mistake somewhere along the way or if there are any issues with the way I am setting up the Lora modules. Thanks for taking the time to help me solve this problem.

Ethan

Your links are blank so I cannot see which LoRa modules you are using.

I am guessing you are using some form of UART front ended LoRa modules, in which case support for them will require someone with specifuc experience of that module.

The standard, and very widly used, SPI based LoRa modules will have lots of working examples to study.

The manual for the RYLR890 shows it to use SPI comms at 3.3V so I think the module number you quote may be wrong.
I can find RYLR895 that has a UART interface that also works at 3.3V. Can you supply a link to the exact modules your using so we can determine if they are suitable for 5V signals/power.

The AT commands manual is located here.

Your code does not check for the OK reply after sending AT commands.
The transmitter code has several setup AT parameters commented out and not all of them are stored in the LoRa module for future use.

I would start of by finding a suitable tutorial on using the module with Arduino and get comms between them working and then adapt that code to add IR control.

I referenced the modules incorrectly they are Reyax RYLR 896 modules and as for the links I'm not sure why they didn't work but I will try to link to them again.

Lora Modules: https://www.amazon.com/gp/product/B07NB3BK5H/ref=ppx_yo_dt_b_asin_title_o04_s02?ie=UTF8&psc=1

DataSheet: http://reyax.com.cn/wp-content/uploads/2017/09/RYLR896_EN.pdf

As for the AT commands commented out I tried to separately set up the module and so I took out the AT commands. Could you elaborate more on how to have the code check for the OK response? All the tutorials I found just sent AT commands in the setup phase and worked fine. Thanks for your help.

I cannot find suitableany code that checks replies so instead I suggest you reset the modules to default.
Follow this tutorial on how to connect the module and then issue the AT+RESET command.
After doing that connect the modules and write code to send/receive a simple message.
If this works okay then you can maybe try altering the ADDRESS & NETWORKID if you prefer not to use the defaults (then test they still communicate).
As your not checking for reply OK commands then you need to be aware that any AT commands you send will need a suitable delay to allow the board to execute that command before issuing another AT command.
Transmitting over LoRa can be quite slow (compared to usual transmission methods) so ensure delays are long enough.

I followed the tutorial and was able to program the modules and receive OK responses when doing it. After this, the modules still did not show any sign of communicating. As for testing it with a simple message, I feel like the message I was sending was pretty simple as it was just a string consisting of 2 characters that the program would then look for to activate a relay board. When sending the same commands through the serial monitor to the receiver I am able to get the relay board to activate and when I connect the transmitter to the serial monitor I can get it to send the AT commands to the computer so I know the code on both sides works up to the modules unless I am misunderstanding something. I also have a delay programmed in after sending any code that I think would do enough to account for the delay in transmission unless I am underestimating how slow it transmits.

Fundamental to troubleshooting issues with RF modules is knowing for sure that the transmitter is actually transmitting.

Probably the easiest way to do this is to use one of the low cost Software Defined Radios (SDR) and check for output.

After resetting the boards and configuring them did you use your same program to test them that reconfigures the parameters or had you commented out the parameter setup code?

Do the board have the antenna soldered onto them and if you had to solder them on then have the boards been used without the antenna connected as this can damage the transmitter chip.

Are you using the voltage divider on the Serial TX pins and powering from 3.3V as 5V can also damage the modules.

Testing with a simple program would be to transmit a simple text message like 'Hello World!' every 5 seconds and see if you receive it on the other module. If you cannot get this to work then we must suspect the modules of your wiring but as you received the OK replies then modules would be most likely.

Going back and looking at your code in more detail I see a couple of problems...
The transmit code will not compile for the Nano as it has no Serial1.
Your transmitting ("AT+SEND=1,6,R1") but assuming you have reset the modules the address should be 0 not 1 and for your payload the length should be 2 and not 6.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.