1.Serial.write(0x0D) is said to take **Carriage Return" action. That means that the cursor will positioned at the beginning of the current line.
The execution of the following codes does not validate my above understanding. I have printed A and then I have executed Serial.write(0x0D) code and then I have printed B. I expected that the character A will be over-written by character B; instead, A and B have appeared along the same line.
I expected that Serialwrite(0x0D) should bring the curson at the beginning of the current line, but it is not doing it. It looks like that the OutputBox of the Serial Monitor just ignores the command.
2.Serial.write(0x0A) brings the cursor at the beginning of the next (new) line. Does it imply that the said code executes Serial.write(0x0D) at the background to bring the cursor at the beginning of the current line and then pushes down the cursor at the beginning of the next (new) line?
3.Serial.println(), according to documentation, executes the following two codes/frames in the order shown:
Serial.write(0x0D);
Serial.write(0x0A);
Serial.println() brings the cursor at the beginning of the next (new) line which means that it is behaving as Serialwrite(0x0A) behaves. Then are there any difference between Serial.write(0x0A) and Serial.println()?
4.Serial.print('\n') brings the cursor at the beginning of the next (new) line. Is it equivalent to Serial.write(0x0A) or Serial.println()?
Would appreciate to hear better/correct clarifications.
The term "Carriage return" derives from old printers where a "carriage" prints the letters over a specific location then moves to the right to the next position of the current row. So don't expect the same on a basic serial monitor (but if you use a serial terminal emulator it will "move" the cursor to the first column then the next character will overwrite the existing one).
Same considerations as above, but for "line feed" that made the paper advance 1 row, without moving the printer head (the "carriage").
Serial monitor simply ignores '\r' (Carriage Return, or 0x0D) and goes to the beginning of the next line just on "'\n' (Line feed, or 0x0A).
Yes, it is equivalent to Serial.write(0x0A); but not to Serial.println(); (see previous points)
I have Serial.write(0x0D) and NOT Serial.print(0x0D) which correctly shows 13 on the OutputBox of the Serial Monitor.
I expected that Serialwrite(0x0D) should bring the curson at the beginning of the current line, but it is not doing it. It looks like that the OutputBox of the Serial Monitor just ignores the command.
Is it Serial.write(0x0D) or Serial.write(0x0A) that is executed first? If Serial.write(0x0D) is executed first, then it brings the cursor at beginning of the current line and then moves the cursor down to the beginning next (new) line. But many posters have said that the Serial Monitor ignores the Serial.write(0x0D) command.
Different operating systems use different codes for end of line.
For example, Windows uses \r\n, but Linux and (probably?) Mac - only the '\n'
I meant that is not only the arduino monitor not used CR because it is bad, the CR code is generally an obsolete command and in most cases is not used at all
Not exactly. It doesn't ignore Serial.write(0x0D) command, it ignores 0x0D characters aka CR in general, and acts 0x0A ('\n') characters aka LF like they were both CR+LF thus moving to the beginning of next line.
Btw, think it as "Linux-style": text files have always just \n as line terminator, \r\n is a Windows crap...
A “dumb” terminal emulator (and the serial monitor certainly qualifies) will frequently include logic to treat “\n”, “\r”, “\r\n”, and “\n\r” all the same: “advance to the beginning of the next line.”
(This avoid unexpected behavior when copying data from one “flavor” of operating system to the “terminal”)
It looks like this occurs deep inside of some Java class that implements something like “display text in a window.”
The main reason that Serial Monitor exists is that it is under control of the IDE. If you have Serial Monitor open and a connection with the Arduino (that you want to upload code to) is open, the IDE will close the port so the upload tool can do the upload without you getting a message that the port is in use.
A second reason is that one does not have to tell a beginner to install another tool (terminal program) for elementary debugging.
Note:
It has nothing to do with understanding AVR architecture.
For example:
To understand the working principles of the Watchdog Timer Module (for example -- a part of architecture) of ATmega328P MCU, a learner performs various experiments on trial-and-error basis. The results are dumped on the OutputBox of the Serial Monitor to asses the progress of learning. So, the Serial Monitor plays an important role (at least to me) in learning the AVR architecture.