RYLR998 and Pro mini - huge latency

I plan to use the above units in a camera trap project. The radio modules have only recently arrived and I am just playing with them now and learning how they work. I have a transmit setup and a separate receive set up.
For testing I have got the tx side to send signal that turned on an LED at the Rx side, the 2 secs later another signal to turn it off.
I am seeing a 1 second delay between the receive circuit getting the signal and the turning on of the LED. What could be causing this?

Here is the TX code

int LED = 4;

void setup() {
  Serial.begin(57600);
  pinMode(LED, OUTPUT);
}

void loop() {

  Serial.println("AT+SEND=2,1,H");
  digitalWrite(LED, HIGH);
  delay(2000);

  Serial.println("AT+SEND=2,1,L");
  digitalWrite(LED, LOW);
  delay(4000);
}

Here is the Rx code

#define LEDPin 6
String incomingstring;

void setup() {
  pinMode(LEDPin, OUTPUT);
  Serial.begin(57600);
  digitalWrite(LEDPin,LOW);

}

void loop() {
  if (Serial.available()) {
    incomingstring = Serial.readString();
    if (incomingstring.indexOf ("H") >0) {
        digitalWrite(LEDPin, HIGH);
      }
    else if (incomingstring.indexOf("L") >0) {
      digitalWrite(LEDPin, LOW);
    }
  }
}

And here is a picture from my scope

Greatfull for any thoughts

Not reading the documentation on how things work would be one possible cause.

From the documentation on Serial.readString

Serial.readString() reads characters from the serial buffer into a String. The function terminates if it times out (see setTimeout()).

And from the documentation on Serial.setTimeout:

Serial.setTimeout() sets the maximum milliseconds to wait for serial data. It defaults to 1000 milliseconds.

1000 milliseconds would be 1 second. So readString will wait 1 second after the last character received before returning. And there is your 1 second delay.

There will also be latency caused by the UART serial interface on the RYLR998 module which first has to receive the serial instructions and convert the data into instructions for the SPI based LoRa module, then the reverse happens on the receive side.

For minimum latency, use the standard SPI based LoRa modules which eliminate all the potential delays caused by the RYLR998 UART conversions.

int LED = 4;

void setup() {
  Serial.begin(57600);
  pinMode(LED, OUTPUT);
}

void loop() {

  Serial.println("AT+SEND=2,2,H#");
  digitalWrite(LED, HIGH);
  delay(2000);

  Serial.println("AT+SEND=2,2,L#");
  digitalWrite(LED, LOW);
  delay(4000);
}
#define LEDPin 6
String incomingstring;

void setup() {
  pinMode(LEDPin, OUTPUT);
  Serial.begin(57600);
  digitalWrite(LEDPin,LOW);

}

void loop() {
  if (Serial.available()) {
    incomingstring = Serial.readStringUntil('#');
    if (incomingstring.indexOf ("H") >0) {
        digitalWrite(LEDPin, HIGH);
      }
    else if (incomingstring.indexOf("L") >0) {
      digitalWrite(LEDPin, LOW);
    }
  }
}

Or just change Rx to read a character since only a character is being sent:

#define LEDPin 6

void setup() {
  pinMode(LEDPin, OUTPUT);
  Serial.begin(57600);
  digitalWrite(LEDPin,LOW);

}

void loop() {
  if (Serial.available()) {
    char c = Serial.read();
    if (c == 'H') {
        digitalWrite(LEDPin, HIGH);
      }
    else if (c == 'L') {
      digitalWrite(LEDPin, LOW);
    }
  }
}
2 Likes

What a facility this forum is! Thank you for such response.

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