2

I have relatively simple code printing some emojis:

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println("Hello world 😊❤👌😘💕👍🤦‍♀️🤦‍♂️😎✔👀");
}

Just in case it doesn't render very well, here's an image on how it looks like in Arduino IDE 2.0.3:

Screenshot of code with emojis rendered

However, the Serial Monitor sometimes displays emojis and sometimes not. It varies from line to line like so:

Hello world 😊���������💕��������♀�������‍♂️😎✔����
Hello world ���������������‍♀️🤦‍♂️😎✔👀
Hello world ��❤���������������������������������♂���😎✔👀
Hello world 😊❤👌😘💕👍🤦‍�������‍�������������
Hello world �������👌😘💕👍🤦‍♀️��������������✔����
Hello world 😊���������👍�����♀���🤦�����️�����������
Hello world ��❤��������👍��‍�����������♂�������✔���

Again, there's how it looks like on my Windows 10 machine:

Screenshot of garbage output

I verified that it's not a mistake in the baud rate. Both, Arduino and PC are set to 9600.

In Arduino IDE 1, the output is not colorful and some emojis are not rendered at all, but the result is much more consistent:

Screenshot of output in Arduino IDE 1

How to fix the scrambled output in Arduino IDE 2?

1
  • 1
    To be clear, this is a problem with handling any multi-byte UTF-8 encoding and potentially another problem on top of that with handling grapheme clusters. When I encountered this for the first time I think it was in using the degree symbol for a temperature reading (code point 0xB0) that encodes in UTF-8 as 0xC2 0xB0. Your odds of seeing the character correctly improve if you Serial.flush() and wait some time before and after multi-byte encodings and do not delay in the middle. In other words, increasing the odds that the Serial Monitor receive an entire UTF-8 sequence in a single buffer.
    – timemage
    Dec 29, 2022 at 18:04

1 Answer 1

2

This is an issue of Arduino IDE 2.0.3. It was reported as issue 589 and issue 1405.

It was fixed on 9th of December 2022 [PR] and I can confirm it is fixed in nightly build 2.0.4-221229.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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