[Solved] What is the character encoding of Arduino's Serial messages?

Hello :)

I have a little problem, I'm writing a .NET program that is basically a serial monitor.

In the Arduino IDE's Serial monitor, message sent from Arduino, such as "Commande reçue", appear correctly.

But in my program, the "ç" is not displayed and shows a "?" instead -> "Commande re?ue".

I am wondering, what is the serial message encoded to, and how can I do to display it correctly in my program.

Here is how I read from the serial port, and fill a textBox with the message:

String^ input = this->serialPort1->ReadExisting();
this->textBox2->AppendText( input );

If I try something like this:

String^ input = "ç \u00e7";
this->textBox2->AppendText( input );

Then what I see in the textBox is: "ç ç"

I'm lost :(

Ps: I'm beginner in writing Windows Form programs so please help me fix the problem, thanks :)

In this link, the encoding is ASCII. http://arduino.cc/en/Tutorial/SerialCallResponseASCII

The encoding from the Arduino is raw - ie whatever you send. There's no BOF characters or anything like that sent before a serial transmission.

When I compile the app using your character, I get the following message;

"debug.ino" contains unrecognized characters.If this code was created with an older version of Processing,you may need to use Tools -> Fix Encoding & Reload to updatethe sketch to use UTF-8 encoding. If not, you may need todelete the bad characters to get rid of this warning

You may need to do as it suggests to get it to work.

You can use Serial.write() and send raw hex code out.
How the other end interprets the code will determine what is displayed.

For example, if you do this:

for (x=0x48; x<128; x=x+1){
Serial.write(x);
delay(250);
}

you will see
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZavcdefghijklmnopqrstuvwxyz
and some punctuation marks because the serial monitor recognizes the ASCII codes.
www.asciitable.com

To confirm: it’s UTF8 encoding. when you type \u00e7 you are specifiying a unicode character using 2 bytes (00 and e7).

That’s why you see 2 characters “Then what I see in the textBox is: “ç ç”” as the textbox is not unicode capable / enabled.

aarondc: That's why you see 2 characters "Then what I see in the textBox is: "ç ç"" as the textbox is not unicode capable / enabled.

Actually the "\u00e7" shows as a "ç" in the textBox, which is correct

aarondc: When I compile the app using your character, I get the following message;

"debug.ino" contains unrecognized characters.If this code was created with an older version of Processing,you may need to use Tools -> Fix Encoding & Reload to updatethe sketch to use UTF-8 encoding. If not, you may need todelete the bad characters to get rid of this warning

You may need to do as it suggests to get it to work.

I don't have this message, also I tried before, the Fix Encoding thing, but it only resulted in the Arduino IDE's Serial Monitor displaying "Commande reçue".

I tried

this->serialPort1->Encoding = Encoding::UTF8;

I tried every possible encodings for this setting, and also many other things like encode the input to another encoding... I can't get it working :(

In the Arduino IDE's Serial monitor, message sent from Arduino, such as "Commande reçue", appear correctly.

But in my program, the "ç" is not displayed and shows a "?" instead -> "Commande re?ue".

It tell you Sun's Java supports unicode better than Microsoft's .Net. It is true since day one.

http://stackoverflow.com/questions/420659/unicode-characters-not-showing-in-system-windows-forms-textbox

use RichTextBox, instead of textBox.

sonnyyu: use RichTextBox, instead of textBox.

Same result with a richTextbox, also tried with different fonts as suggested... :(

Edit: Solved :D ! But I'm not sure it's the correct way to do it:

this->serialPort1->Encoding = Encoding::Default;

(working with both richTextBox and textBox )

I believe that the problem is in SerialPort. Try to play with SerialPort.Encoding Property http://msdn.microsoft.com/it-it/library/system.io.ports.serialport.encoding.aspx http://msdn.microsoft.com/it-it/library/system.text.encoding.aspx

Edit: I see that you resolved during my typing.

zoomx: I believe that the problem is in SerialPort. Try to play with SerialPort.Encoding Property http://msdn.microsoft.com/it-it/library/system.io.ports.serialport.encoding.aspx http://msdn.microsoft.com/it-it/library/system.text.encoding.aspx

Edit: I see that you resolved during my typing.

Desole. Je ne parle pas Italian ;-)

Yeah I tried previously every Encoding, BUT Default (I didn't know it was an encoding type), I thought it wouldn't change anything, but in fact that was the (or, one) solution!

Thanks all anyway for trying to help me :)

aarondc: Desole. Je ne parle pas Italian ;-)

Funny, the pages are in english for me but I noticed that all around is in italian because I used "Original" instead the tranlation. These are in british english but you can change the language in the right top of the page. http://msdn.microsoft.com/en-gb/library/system.io.ports.serialport.encoding.aspx. http://msdn.microsoft.com/en-gb/library/system.text.encoding.aspx