serial output missing newline or cr in serial monitor

hi all

my arduino mega shows output ( see below ) as one (1) line .
there are no new lines or CR in the line.
Can you girls/guys help me out where i put the newline or CR

the output from my serial monitor:

t2.txt="12/03/21 13:13:17"⸮⸮⸮t2.txt="12/03/21 13:13:18"⸮⸮⸮t2.txt="12/03/21 13:13:18"⸮⸮⸮t2.txt="12/03/21 13:13:19"⸮⸮⸮t2.txt="12/03/21 13:13:19"⸮⸮⸮t2.txt="12/03/21 13:13:19"⸮⸮⸮t2.txt="12/03/21 13:13:20"⸮⸮⸮t2.txt="12/03/21 13:13:20"⸮⸮⸮t2.txt="12/03/21 13:13:21"⸮⸮⸮t2.txt="12/03/21 13:13:21"⸮⸮⸮t2.txt="12/03/21 13:13:21"⸮⸮⸮t2.txt="12/03/21 13:13:22"⸮⸮⸮t2.txt="12/03/21 13:13:22"⸮⸮⸮t2.txt="12/03/21 13:13:23"⸮⸮⸮t2.txt="12/03/21 13:13:23"⸮⸮⸮t2.txt="12/03/21 13:13:23"⸮⸮⸮t2.txt="12/03/21 13:13:24"⸮⸮⸮t2.txt="12/03/21 13:13:24"⸮⸮⸮t2.txt="12/03/21 13:13:25"⸮⸮⸮t2.txt="12/03/21 13:13:25"⸮⸮⸮t2.txt="12/03/21 13:13:25"⸮⸮⸮t2.txt="12/03/21 13:13:26"⸮⸮⸮t2.txt="12/03/21 13:13:26"⸮⸮⸮t2.txt="12/03/21 13:13:27"⸮⸮⸮t2.txt="12/03/21 13:13:27"⸮⸮⸮t2.txt="12/03/21 13:13:27"⸮⸮⸮t2.txt="12/03/21 13:13:28"⸮⸮⸮t2.txt="12/03/21 13:13:28"⸮⸮⸮t2.txt="12/03/21 13:13:29"⸮⸮⸮t2.txt="12/03/21 13:13:29"⸮⸮⸮t2.txt="12/03/21 13:13:29"⸮⸮⸮t2.txt="12/03/21 13:13:30"⸮⸮⸮t2.txt="12/03/21 13:13:30"⸮⸮⸮t2.txt="12/03/21 13:13:31"⸮⸮⸮t2.txt="12/03/21 13:13:31"⸮⸮⸮

the code to put all in one (1) line

void setup() {
  Serial.begin(9600);
  Serial1.begin(9600);
  Serial2.begin(9600);
}
void loop() {
  while(Serial1.available()) {          // If anything comes in Serial 1 (pin  19)
   
    Serial.write(Serial1.read()); 
   
  }
}

many thanks in advance
menno

somehow there is some kind of separator ⸮⸮⸮And it would help to figure out what it is exactly.

void loop() {
  while(Serial1.available()) {          // If anything comes in Serial 1 (pin  19)
   
    byte rd = Serial1.read();
    Serial.print(rd, HEX); // or DEC 
    Serial.print(", ");
  }
}

This should show you also what the 'non-printable' characters are. Then you can filter for those and replace them with '\n' & '\r'

thx man !
i looked it up , the result :
64, 69, 6D, 3D, 32, 30, FF, FF, FF,

so those ⸮⸮⸮ are : FF FF FF
Can you help me out how i can replace these ⸮⸮⸮ to a \n or \r ?

many thanks in advance
menno

Read the available byte into a variable. Test its value and if it is equal to 0xFF output a '\n' or '\r' instead

Serialxx.read() returns -1 (0xFF) when there is nothing to be read.
So this looks like some code somewhere may not be checking Serialxx.available()

drmpf:
Serialxx.read() returns -1 (0xFF) when there is nothing to be read.
So this looks like some code somewhere may not be checking Serialxx.available()

While that is true, it is probably a communication with a Nextion that uses three 0xFF as a message delimiter.

OP: I have a library that handles serial communication and is capable of handling the Nextion format.

#include <WhandallSerial.h>  // https://github.com/whandall/WhandallSerial

// simple handler just prints some infos about the received line

void processLine(const char* buf) {
  Serial.print(F("len = "));
  Serial.print((uint8_t)buf[-1]);
  Serial.print(F(", strlen = "));
  Serial.println(strlen(buf));
  Serial.println(buf);
}

SSerial nextionSerial(Serial1, processLine); // used serial and handler

void setup() {
  Serial.begin(250000);
  Serial1.begin(9600);
  nextionSerial.begin(64, optTripleFF); // buffer size and options, maybe +optKeepDlm
}

void loop() {
  nextionSerial.loop();    // collect chars and call handler for each line
}

Serialxx.read() returns -1 (0xFF) when there is nothing to be read.
So this looks like some code somewhere may not be checking Serialxx.available()

Looking at the code, i would say the transmitting device is sending them on purpose.

so those ⸮⸮⸮ are : FF FF FF
Can you help me out how i can replace these ⸮⸮⸮ to a \n or \r ?

Let's assume that we just want every 3rd 0xFF (or 255) to be changed into a '\r'

void loop() {
  static byte count = 0;
  while(Serial1.available()) {          // If anything comes in Serial 1 (pin  19)
   
    byte rd = Serial1.read();
    if (rd == 0xFF) {
      count++;
      if (count > 2) {
        Serial.print('\r') // or Serial.write(13);
        count = 0;
      }
    }
    else Serial.write(rd); 
  }
}

Pretty much what Bob was saying.

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