Serial.println unicode characters

Dears,

i need to print non-ascii (unicode) characters , but the Serial.print print the ascii only, is there any way to print it??

thanks.

is there any way to print it??

Look at the source code for Serial.print(). There are many overloads, for printing different kinds of values. In the end, they all call Serial.write() to send a single byte.

What kind of variable are you using to hold these non-ASCII characters?

Thanks Dear,

i want to print the arabic leters, what do u mean of source code, “Source code of what”?

Source code of what"?

The source code for the Serial.print() method(s). Serial is an instance of the HardwareSerial class, so look at HardwareSerial.cpp (which you do have) to see what Serial.print() does FOR THE UNSPECIFIED VARIABLE TYPE you are using.

is there any way to print arabic letters on the serial??

Use UTF8 encoding? Have the other end assume this.

I have tried this sketch as well as many others that attempt to send utf-8 data and no matter what I can't get the special characters to display properly. I am using a debug serial port and listening using Putty. It is set to UTF-8 encoding. If I do a simple loopback test directly in Putty without using the arduino ide the characters are correct. If I send them using serial via arduino they are rarely correct. I say rarely because sometimes they do print correctly. I am using IDE 1.8.4. I saw mention of timing issues on github - "The serial monitor doesn't correctly support UTF-8 this is an unresolved issue, it may seems to work but it doesn't, a timing issue exists, for details look here:

2430 (comment)

PuTTY supports shaping of Arabic text and bidirectional text display, which means that if you send text written in the basic Unicode Arabic alphabet then it will convert it to the correct display forms before printing it on the screen. Ensure this is enabled in the preferences and send properly formed unicode stream

Arabic is a Unicode block consisting of 255 characters from 0x0600 to 0x06FF that lets you encode the standard letters and diacritics. if needed you have Arabic Supplement which is another Unicode block that encodes Arabic letter variants consisting of 48 characters in the range 0x0750 to 0x077F, Arabic Mathematical Alphabetic Symbols etc and there are more, cf this page for example. I don't know if PuTTY supports the extended sets

There is no way to store the strings directly in the IDE in a char array though

const char arabic[] = "العربية"; // will fail

I think you will have to painfully store the byte stream which is the well formatted unicode representation of your string

The Arabic letter alef ا for example is in unicode U+0627

العربية will probably need to be a binary flow which then needs to be byte by byte inserted in your array

0x0627 ,0x0644 ,0x0639 ,0x0631 ,0x0628 ,0x064a ,0x0629 // ا ل ع ر ب ي ة from right to left (I obtained this byte stream from this web site UTF16 representation)

const byte arabic[] = {[tt]0x06,0x27 ,0x06,0x44 ,0x06,0x39 ,0x06,0x31 ,0x06,0x28 ,0x06,0x4a ,0x06,0x29}; // العربية ‎‎[/tt]

I would try to send this raw byte stream directly through the Serial port using Serial.write() and not print

PS: Hopefully I did not abuse your language, I used google translate to get the word "العَرَبِيَّة‎‎" for "Arabic".... apologies in advance if it means something else.

You can use this as the string:

Serial.println("\u0627\u0644\u0639\u0631\u0628\u064A\u0629");

each value has a "\u" in it. this signifies unicode (specifically UTF16 format) and the four numbers after it represent the hexadecimal representation of a certain characters. This can also be done with the wchar_t data type, which is a type of char data type that can hold "wide" chars, like these, that require extra memory. For more things you may want to convert you can visit this site: https://unicodelookup.com.

Hopefully this is what you were looking for.