Why does Serial.println('S') become "S\r" through my serial port?

Good afternoon,

http://puu.sh/qDr9H/f8e897e7c6.png

I attached a photo which reveals my issue. My sketch only serial prints a capital "S" and in my C# code I set a string equal to what I sent from the Arduino.

Look on line 20 of the C# code I have just set my string equal to what the Arduino sent. Keep in mind that when I "Console.WriteLine" within C# it prints a normal "S", not "S\r". Why does the value suddenly become "S\r"? You can see I circled it in red at the bottom of the photo.

Any information is helpful! ;D

Thank you

I couldn't find you attachments (might be because I'm using my phone), but I think I know what's going on.

The "\r" stands for carriage return, which I'm guessing is appended to the sent data "S" when processed with the .print method. Your C# code extracts the "\r" and only displays "S".

Serial.println is doing exactly what it is supposed to do. It is not the same as Serial.print.
Look them up in the online documentation.

Pete

Thanks a lot for the quick reply!

I had a look at the online documentation and it says that serial print statements are followed by a carriage return.

Is there a way to serial print without a carriage return? Just the letter "S" for example. I can always adjust my code to accept carriage return, but its not as fun :stuck_out_tongue:

Alex

Serial.print() does not append a carriage return. Serial.println() does.

Actually, Serial.println() is most likely appending both carriage return (\r) and line feed (\n). Your SerialPort::ReadLine() method on the computer probably removes the \n.

alexanderstroborg:
I had a look at the online documentation and it says that serial print statements are followed by a carriage return

You need to read more carefully.

Also worth looking at Serial.write() which bypasses all of the print format processing.