NL and CR on serial bus / SOLVED

Hello I have a problem. While using REYAX RYLR896 radio (controlled by serial comands) I get this +ERR=1. Which is "There is not “enter” or 0x0D 0x0A in the end of the AT Command."
But as you can see in my code I have the NL and CR in the string end. Why am I getting this error?

String zpr = "AT";
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial1.begin(115200);
}

void loop() {
  // put your main code here, to run repeatedly:
  zpr = zpr + "\r\n";
  delay(5000);
  Serial1.print(zpr);
  while(true){
    if(Serial1.available()){
      Serial.print(Serial1.readString());
    }
  }
}

try to

Well, strange behaviour, btw just a few things:

  1. "String" class is deprecated, and use a String variable just to have "AT" command is useless
  2. If you want to do something just once, put it in setup(), not in a "while(true)" inside the loop()

So, IMHO better doing this:

void setup() {
  Serial.begin(115200);
  Serial1.begin(115200);
  Serial1.println();

  delay(5000);
  Serial1.println("AT");
  while(true) {
    if(Serial1.available())
      Serial.print(Serial1.readString());
  }
}

void loop() {
}

Give it a try and let me know what happens.

Good idea, Ill try it, thanks!

Yeah, that was just a leftover, but thank you.

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