In my program, using the serial monitor as the output...
str1 = "hello";
str2 = '\r';
str3 = "there";
Serial.println(str1 + str2 + str3);
What I get is hellothere
Why doesn't the \r give a careriage return?
In my program, using the serial monitor as the output...
str1 = "hello";
str2 = '\r';
str3 = "there";
Serial.println(str1 + str2 + str3);
What I get is hellothere
Why doesn't the \r give a careriage return?
Always show us your ‘current’ compete sketch. Use
CTRL T to format the sketch.
Please use code tags.
Use the </> icon in the posting menu.
[code] Paste sketch here. [/code]
“What I get is hellothere”
Is that right?
println the 'ln' in println gives a carriage return.
Try:
str1 = "hello \r";
str3 = "there";
Serial.print(str1);
Serial.println(str3);
You cannot add character strings your way.
on an old printer \r without \n would return the head to the beginning of the line without moving the paper. the line would be overwritten. Serial Monitor doesn't do that. but telnet client with \n without \r goes a line down but not to the beginning of the next line
without \r
I got
stairs
Got it.
Like said, the \r does not seem to do anything in the serial monitor.
barryjo:
Got it.Like said, the \r does not seem to do anything in the serial monitor.
Because the serial monitor is not a full featured display terminal.
The arduino serial monitor is a piece of garbage. The only thing good is the autoclose when uploading a sketch, and that doesn't even work all the time.
For anything other than quick tests, I recommend using a real serial terminal program. I use hterm - the UI is a little rough, but it has an incredible array of features. I love how it displays the state of the modem control inputs - that effectively gives you 4 active low digital inputs on your computer that you can see visually. I used it intensively when debugging a complicated serial application (I had this contraption for debugging a serial line, because I needed to be able to watch what was going down both lines on a serial adapter and inject characters onto one of them, but not backpower it if it wasn't powered, and monitor a line that indicated activity and would have blinked an LED if one was connected, but it was just connected with a flying lead. So I had two serial adapters and 2 LM339's, and I generated a reference voltage by dividing the voltage from the system under test (I had vcc on the header - it was a 6-pin FTDI style header, but on a line that had other parts on it) - comparator used that to listen to each line without interfering with it, and then I did a similar thing with the tx lines of each adapter, so I could listen to the serial line, or inject characters on it, without ever risking backpowering it) - that was fun. )