Go Down

Topic: [Solved] What is the character encoding of Arduino's Serial messages? (Read 26845 times) previous topic - next topic

guix

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:
Code: [Select]

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


If I try something like this:
Code: [Select]

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

cyclegadget


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



Good links: Eagle tutorial= http://www.youtube.com/playlist?list=PLDE1858BD83D19C70
General Arduion tutorials = http://tronixstuff.wordpress.com
http://www.gammon.com.au/forum/bbshowpost.php?bbtopic_id=123

aarondc

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.

aarondc

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

Quote

"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.

CrossRoads

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
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

aarondc

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.


guix


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


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

Quote

"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
Code: [Select]

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

sonnyyu

Quote
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.

guix

#8
Jun 19, 2013, 04:06 pm Last Edit: Jun 19, 2013, 04:33 pm by guix Reason: 1

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:
Code: [Select]

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

(working with both richTextBox and textBox )


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.

aarondc


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 ;-)

guix

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

zoomx


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

Go Up