Let us do some experiments to get the answers of your queries.
1. This is the layout (Fig-1) of Serial Monitor (SM) of Arduino IDE.
Figure-1:
2. You select 'Newline (LF)' option in the 'Line ending tab', enter C in the InputBox of SM and then click on the Send button. As a result, 0x43 (ASCII Code of character C) and 0x0A (ASCII Code of Newline character) will be travelling towards Arduino which we can catch and send them back to SM for validation.
Sketch:
void setup()
{
Serial.begin(9600);
}
void loop()
{
byte n = Serial.available();
if (n != 0)
{
char x = Serial.read();
Serial.print(x, HEX); //shows: 43 and A (leading 0 is missing)
}
}
3. Repeat Step-2 with option 'Carriage return (CR)' in the 'Line ending tab'.
The SM should show: 43 and A (leading 0 is missing)
4. Repeat Step-2 with option 'Both NL & CD' in the 'Line ending tab'.
The Sm shows: 43, 0D, and 0A.
5. Repeat Step-2 with option 'No line ending' in the 'Line ending tab'.
The Sm shows: 43
6. What codes/non-printable character is involved with this: \n.
It is the 'Newline/LF' character
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println();
Serial.print('\n', HEX); //shows: 0A; Newline charcater (LF)
delay(2000);
}
7. Working principle of:
byte m = Serial.readBytesUntil('\n', Arr, 5);
(1) You select 'Newline' option in the 'Line ending tab', enter ABCDE in the InputBox of SM and then click on the Send button. ABCDE will be stored in the array named Arr[]; code for \n will not be stored in Arr[]. m is equal to 5 indicating number of charcaters received. The function will terminate as 5 charcaters have been received; it will not wait to check if \n has arrived or not.
(2) You select 'Newline' option in the 'Line ending tab', enter ABC in the InputBox of SM and then click on the Send button. ABC will be stored in the array named Arr[]. m will be equal to 3 indicating the number of charcaters received. As declared amount (5) charcaters have not arrived/received, the function will wait until it finds the terminating character \n; once \n is detected, the function will terminate. The code for \n will not be stored in Arr[].
(3) If you don't enter any character in the InputBox within a 1-sec (the default timeout period), the function will automatically terminate with m = 0.