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:
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:
How to fix the scrambled output in Arduino IDE 2?
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.