Hello folks,
Since two weeks I have two of these LoRa transceivers. I got them working with Hardware Serial, with this code:
String message;
int prevTime;
bool sendON = true;
void setup() {
// put your setup code here, to run once:
setUp();
pinMode(2,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
blink();
receive();
if (message == "ON"){
digitalWrite(2,HIGH);
}
if (message == "OFF"){
digitalWrite(2,LOW);
}
}
void blink() {
if (millis() - prevTime > 2000) {
prevTime = millis();
if (sendON == true) {
send("ON", 1);
sendON = false;
}
else {
send("OFF", 1);
sendON = true;
}
}
}
void receive() {
if (Serial.available() == 1){
String readString = Serial.readString();
int delimiter, delimiter_1, delimiter_2, delimiter_3;
delimiter = readString.indexOf(",");
delimiter_1 = readString.indexOf(",", delimiter + 1);
delimiter_2 = readString.indexOf(",", delimiter_1 + 1);
delimiter_3 = readString.indexOf(",", delimiter_2 + 1);
int lengthMessage=readString.substring(delimiter_1+1,delimiter_2).toInt();
String message = readString.substring(delimiter_2 + 1 , lengthMessage);
}
}
void send(String Transmit, int address) {
int TransmitLength = Transmit.length();
String message = "AT+SEND=" + String(address) + "," + String(TransmitLength) + "," + Transmit + "\n\r";
Serial.println(message);
}
void setUp() {
Serial.begin(115200);
delay(1000);
Serial.print("AT+RESET\r\n");
delay(500);
Serial.print("AT+PARAMETER=12,6,1,7\r\n");
delay(100); //wait for module to respond
Serial.print("AT+BAND=868000000\r\n"); //Bandwidth set to 868.5MHz
delay(100); //wait for module to respond
Serial.print("AT+ADDRESS=2\r\n"); //needs to be unique
delay(100); //wait for module to respond
Serial.print("AT+NETWORKID=6\r\n"); //needs to be same for receiver and transmitter
delay(100); //wait for module to respond
Serial.print("AT+CRFOP=15\r\n");
delay(1000);
}
But the disadvantage of using Hardware Serial is that you can’t communicate with the arduino without sending that same message to the LoRa module (because the LoRa module is connected to the Hardware Serial pins as well) .
To fix this I tried to use SoftwareSerial, so I don’t use Hardware Serial for communicating with the LoRa module. I changed the baudrate of the module; tried different pins and different arduino’s , but that didn’t work. I’ve tried NeoSWSerial and AltSoftSerial as well but still no result.
When I open the Serial Monitor with this sketch running
#include <SoftwareSerial.h>
SoftwareSerial LoRa(2, 3); // RX, TX.
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
LoRa.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Goodnight moon!");
// set the data rate for the SoftwareSerial port
LoRa.println("AT");
}
void loop() { // run over and over
if (LoRa.available()) {
Serial.write(LoRa.read());
}
if (Serial.available()) {
LoRa.write(Serial.read());
}
}
// I tried saving the received data in a char as well but didn't work as well
I get something like “⸮⸮⸮⸮⸮”
So in short: is it possible to communicate with the Reyax RYLR896 without using Hardware Serial?
Connections:
Arduino - LoRa Module
RX - TX
TX → voltage divider circuit (using as R1 5.1 kΩ and R2 10 kΩ) → RX
3.3v - VVD
GND - GND
Any help is much appreciated