I am printing some ASCII art to the Serial monitor from Arduino UNO, with some success. However, using string literals uses more memory than I would like. I wanted to try constructing the strings/chars from other data types so that I can manipulate the data and print the ascii art without storing it in string literals.
However, I have found that there seems to be no way to print UTF-8 characters other than from a string literal. Is this the case? Is there no way to construct a string containing characters that have numeric values that are too big for char
?
As an example, to print "▓" works fine as a String literal but, it seams, no other way.
Serial.println("▓"); // works fine
Serial.println('▓'); // char can't store value
Serial.println(String('▓')); // char can't store value
Serial.println(0x2593); // just prints the numeric value
Serial.println((char)0x2593); // char can't store value
Serial.println((wchar_t)0x2593); // doesn't work
Serial.println(String(0x2593)); // doesn't work
Serial.println(String((wchar_t)0x2593)); // doesn't work
Similarily with write() instead of print():
Serial.write("▓"); // Works fine
Serial.write('▓'); // char can't store value
Serial.write(0x2593); // just prints the numeric value
Serial.write((char)0x2593); // char can't store value
Serial.write((wchar_t)0x2593); // doesn't work
I also tried deriving new component strings from a string literal using substring()
and charAt()
. Neither works. Both produce � in the output.
String((char)65)
constructs the string "A" from the numeric value 65. Neither String((char)0x2593)
nor String((wchar_t)0x2593)
produce the desired results. Is there a way to construct a string from numeric values that are too big to store in 'char'?
Serial.println("\u2593");