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

Hello :slight_smile:

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 :frowning:

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

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.

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 :frowning:

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.

use RichTextBox, instead of textBox.

sonnyyu:
use RichTextBox, instead of textBox.

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

Edit: Solved :smiley: ! 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

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
SerialPort.Encoding Proprietà (System.IO.Ports) | Microsoft Learn
Encoding Classe (System.Text) | Microsoft Learn

Edit: I see that you resolved during my typing.

Desole. Je ne parle pas Italian :wink:

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 :slight_smile:

aarondc:
Desole. Je ne parle pas Italian :wink:

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.
SerialPort.Encoding Property (System.IO.Ports) | Microsoft Learn.
Encoding Class (System.Text) | Microsoft Learn