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:
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 Answer 1
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.
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.