1

I'm writing a sketch for a Wemos D1 Mini to display a web page. This works and I can get Unicode characters to display, but if I try to use ones with surrogate pairs like 🔊 I get a compile error;

  s += "\uD83D\uDD0A";

Error

\uD83D is not a valid universal character

How can I get this character in my code?

  • Google the error message "\uD83D is not a valid universal character" and you fill find lots of answers. – user31481 Jul 12 '17 at 22:27
1

There is a nifty new feature in C++11 called string literal, this example shows how to use it with any single line or multi line or utf8 text. You just define starting and ending sequence, in following case --- (starting sequence becomes R"---( and ending sequence )---") and make sure that this sequence does not appear in encapsulated text. This is great for integrating websites into arduino projects:

static const char _index_html[] PROGMEM = R"---(
<html>
<head>
<link rel="icon" type="image/png" href="/favicon.png"/>
</head>
<body>
...
</body>
</html>
)---";
  • Okay, but what does that have to do with the SMP? Or anything outside ASCII for that matter? – Ignacio Vazquez-Abrams May 9 '18 at 12:18
  • If he had used any unicode capable editor, he could just copy/paste any unicode symbols without caring how to encode them - no need to use escaping sequences. Also this answers shows how to easily integrate mutliline HTML code into arduino project – gabonator May 9 '18 at 12:30
0

After some trial and error, I got it using the python style u"\U0001F50A" without the leading u of course

  s += "\U0001F50A";

Too bad I didn't think about googling the error msg, would have saved me some time.

  • 1
    Can you use pure UTF-8 characters in the source code ? It is a risk, because everything should be able to handle them. I think it should work. At least this forum can handle pure UTF-8 characters: ±10 °C, 10 µm, 1 kΩ, ¿ – Jot Jul 13 '17 at 1:03
  • Actually, you can. I didn't even try that. – Musa Jul 13 '17 at 2:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.