Arduino Nano SoftwareSerial returns weird characters

Hello,
I have connected Reyax RYLR998 Lora modules to Arduino Nano as given below

Here is code

#include <Arduino.h>
#include <SoftwareSerial.h>

const String BAND_LORA_INDIA="868500000"; 
const String NETWORKID_LORA="5";                                
const String ADDRESS_LORA_NODE_GATEWAY="55";
const String ADDRESS_LORA_NODE_VALVE="22";
const String ADDRESS_LORA_NODE_PUMP="33";
const String PASSWORD_LORA ="123";
//I tried all these BAUD Rates 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 31250, 38400, 57600, 115200
#define BAUD_RATE_LORA_FOR_ARDUINO 115200 

int WAITING_BETWEEN_TWO_AT_COMMAND_ARDUINO = 300;

SoftwareSerial LoRa(2, 3);

void setup()
{
  Serial.begin(9600);

  LoRa.begin(115200);
  setLoraConfig();
  delay(2000);
  LoRa.print("AT+BAND=" + BAND_LORA_INDIA + "\r\n"); 
  delay(2000);
  checkLoraConfig();

}

void setLoraConfig()
{
  LoRa.print("AT\r\n"); // Just a check if the module is well connected
  delay(WAITING_BETWEEN_TWO_AT_COMMAND_ARDUINO);
  LoRa.print("AT+ADDRESS=" + ADDRESS_LORA_NODE_VALVE + "\r\n"); 
  delay(WAITING_BETWEEN_TWO_AT_COMMAND_ARDUINO);
  LoRa.print("AT+NETWORKID=" + NETWORKID_LORA + "\r\n"); 
  delay(WAITING_BETWEEN_TWO_AT_COMMAND_ARDUINO);
  LoRa.print("AT+IPR=" + String(BAUD_RATE_LORA_FOR_ARDUINO) + "\r\n"); 
  delay(WAITING_BETWEEN_TWO_AT_COMMAND_ARDUINO);
  LoRa.print("AT+RESET\r\n"); 
  delay(WAITING_BETWEEN_TWO_AT_COMMAND_ARDUINO);
  LoRa.print("AT+BAND=" + BAND_LORA_INDIA + "\r\n"); 
  delay(WAITING_BETWEEN_TWO_AT_COMMAND_ARDUINO);
  LoRa.print("AT+CPIN=" + PASSWORD_LORA + "\r\n"); 
  delay(WAITING_BETWEEN_TWO_AT_COMMAND_ARDUINO);
}
void checkLoraConfig()
{
  SerialLog("\n\ncheckLoraConfig\n");
  LoRa.print("AT?\r\n");
  String serialPayload = LoRa.readString();
  SerialLog("\nModule responding?");
  SerialLog(serialPayload);

  LoRa.print("AT+ADDRESS?\r\n");
  serialPayload = LoRa.readString();
  SerialLog("\nAddress:");
  SerialLog(serialPayload);

  LoRa.print("AT+NETWORKID?\r\n");
  serialPayload = LoRa.readString();
  SerialLog("\nNetwork id:");
  SerialLog(serialPayload);

  LoRa.print("AT+IPR?\r\n");
  serialPayload = LoRa.readString();
  SerialLog("\nUART baud rate:");
  SerialLog(serialPayload);

  LoRa.print("AT+BAND?\r\n");
  serialPayload = LoRa.readString();
  SerialLog("\nRF frequency:");
  SerialLog(serialPayload);

  LoRa.print("AT+CRFOP?\r\n");
  serialPayload = LoRa.readString();
  SerialLog("\nRF output power:");
  SerialLog(serialPayload);

  LoRa.print("AT+MODE?\r\n");
  serialPayload = LoRa.readString();
  SerialLog("\nWork mode:");
  SerialLog(serialPayload);

  LoRa.print("AT+PARAMETER?\r\n");
  serialPayload = LoRa.readString();
  SerialLog("\nRF parameters:");
  SerialLog(serialPayload);

  LoRa.print("AT+CPIN?\r\n");
  serialPayload = LoRa.readString();
  SerialLog("\nAES128 password of the network::");
  SerialLog(serialPayload);
}

void loop()
{
 
}

Here is output on serial monitor, please note its not issue of serial monitor( i just confirmed it by comparing incoming string and triggering relay, this is not in code and connection diagram)

Serial monitor output

---- Opened the serial port COM8 ----
19:22:48:623 -> 
19:22:48:623 -> 
19:22:48:623 -> checkLoraConfig
19:22:49:639 -> 
19:22:49:639 -> Module responding?B'?B'?B'?B'?&A
                                                ?Pn?L?'?V??B'?B'?B'?B&?B&?'CB'?
19:22:50:648 -> Address:@'?
19:22:51:655 -> Network id:B'?
19:22:52:662 -> UART baud rate:B'?
19:22:54:573 -> RF frequency:B'?'C?Vn?L?'??'?
19:22:55:566 -> RF output power:@'?
19:22:56:564 -> Work mode:B'?
19:22:57:571 -> RF parameters:B'?
19:22:58:586 -> AES128 password of the network::B?
19:22:58:619 -> 
19:22:58:619 -> Payload sent: AT+SEND=55,25,1|30|40|45.00|35.00|40.00
19:23:01:585 -> 
19:23:01:585 -> 
19:23:01:618 -> 

I have tried all BAUD rates for SoftwareSerial(), when BAUD rate is 115200 it sometimes gives better result but for 57600 it gives complete junk characters.

3.3V pin of Nano cannot provide enough current for your module. Use an external 3.3V regulator such as mcp1700.

you are receiving characters from the LoRa node at 115200baud and outputting to the serial monitor at 9600baud which could cuase loss/corruption of data - run the serial monitor at 115200baud
also SoftwareSeial can cause problems at high baudrates - suggest you run the LoRa device at 19600baud
also the RYLR998 specification states it is 3.V logic device - it can be damaged connecting it directly to a Nano which use 5V logic - use a level converter on the Nano Tx signal to the RYLR998 Rx

Yes, i tried changing Baud rate of hardware serial as well.
Yes, i tried lowering Baud rate,but result worse,115200 atleast sometimes gives me correct result,20% correct.
Lowering Baud rate gave complete junk

But same Lora module works perfectly with ESP82866,i mean with 3.3v of node MCU

the ESP8266 is a lot faster and more powerful than a Nano
I assume you were using espsoftwareserial
if you are using LoRa peer to peer make sure the parameters of both devices are identical
EDIT: I assume when you change the LoRa baudrate on the nano you change the RYLR998 baudrate to match using the AT+IPR= command?

I'd go slightly slower than that and use 19200. :grinning:

Yes, i did charge Baud rate of lora,and both modules have same frequency,network id.
Surprise observation is,same code works perfectly with other Arduino nano with same processor Atmega 328P.

sounds like you may have a faulty nano? can you try another?

ok will try, if its faulty it should not allow be to upload program and should not behave differently with change in BAUD rate? these are my opinions,I may be wrong.

could be faulty nano, faulty USB cable, faulty wiring, etc etc
try to eliminate the possible problems one by one

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