Serial Monitor produces gibberish

After uploading an updated sketch and going to monitor output it seems the baudrate is out of sync.
Both the sketch and the monitor are on the same speed setting but still the output is not readable.
Sometimes after closing/reopening the monitor the results become ok, but that is no guarantee.
I tested 9600 and 115200 with different sketches.

When using an external monitor it works correct.

It sounds like you have not included Serial.begin(115200); in your code. In the next line put Serial.Print(\n\n\tHi Xinonix!\n\n"); The 115200 is the baud rate. Let us know how this works. If it doesn't check to be sure you have chosen the correct board and if so posting your code would help.

Hi @Xinonix

Please provide a sample of the unreadable output.

The baudrate in the sketch is identical as the baudrate in the monitor, so that is not the cause of the issue.

maybe related:
image

or
image
while the monitor is actually showing updates outputs.

This issue is being tracked by the Arduino IDE developers here:

These notifications occur in my Serial Monitor as well, where I have no unexpected gibberish.

By the way, I'm still waiting for that sample I requested. I don't notice any gibberish in the screenshots you shared.

Here is the example, it does not happen al the time, so sorry for the waiting caused:

After complete shutdown of Arduino ide and restart I got:

Same start as previous image followed by proper display
I,�!�$TY�c %C���@BE��D"�$��\ :'e�&I9��,�

Q �

�F J %�DL��� lPT �E}�F!D�T������Q��J�,���3S,x�Hz�J��c����Q�p���&0�0��FI�edj��Db����1�

:D 7��D���&�r��]�2i �L�� zQX��|@�A�FbT�H���(��

��8H��Rg�}�F�qh�0�� (��Q������������2'mDZ$,�!�i c��Q�pT���F�w���&�8�I��1

�P�8H�6����@�FIX ��D�9U�,��B��"m�D��,�QtJ\��F �8�F!�q1 ��$ -�F�8R�M�k(%P��%�+��2��,�!�����4rH��4s@h�F�J �� i�$�|�F�P�T]��D�\�&�2$b��1���I��<���&42$c��#�@���A$A����R�S,��F�Q��� (��D �9T$X�H�y'U�RT��T�i�����&�V$,�Q��%e����E%A�� 4&!$�4

%K�D" L\����J\h�!B���Rg���F��4,����AQ�A��$���$�ILI9341 Test!

Display Power Mode: 0x7F

MADCTL Mode: 0x7F

Pixel Format: 0x7F

Image Format: 0x7F

I don't know if this might be related, I print to console and sometimes some characters fail to print properly:
image

Hi. Unfortunately, I have not come up with a good idea about the cause or solution for this style of output. The reason I was asking for a sample is because there are a couple different known issues that produce distinct signatures of "gibberish". Unfortunately, this sample does not match. I had a hypothesis that it could be caused by this bug when the merged serial streams have different baud rates:

Interestingly, I found that each port's data is processed at the correct baud rate set in its IDE window, so e.g., output from one board at 9600 baud and another at 115200 baud can coexist in the same Serial Monitor without any gibberish.

Another very distinctive flavor is caused by lines of text overwriting each other:

Clearly that is not the one you have.

Now this one I do recognize:

When I use a different serial console I get following for the degree character:
Temp: 20.84°C
image
while the code is =

 Serial.printf("TU: %d Temp: %.2f°C, Hum: %.2f\%% , pres: %.2fhPa\n",aRecord->data.tu, aRecord->data.temperature, ...

So it must be something in the compiler and not in the serial monitor for this specific error. while the monitor sometimes displays the correct representation, ... and that is weird

That is unexpected to me. When using the demo sketch I provided in the issue linked above, the output is corrupted in the Arduino IDE 2.x Serial Monitor but it is displayed just as expected in the Arduino IDE 1.x Serial Monitor.

This holds true regardless of which IDE I used to compile and upload the sketch.

Which "different serial console" are you using?

If you have Arduino IDE 1.x installed, do you get the expected output from its Serial Monitor?

Please provide a minimal demonstration sketch. For example:

void setup() {
  Serial.begin(9600);
}
void loop() {
  Serial.println("°");
  delay(200);
}

I wrote my own monitor solution :slight_smile:

Here is the code:

void setup() {
  Serial.begin(115200);// put your setup code here, to run once:

}

void loop() {
  float temp = random(18,22)*1.0;
  Serial.printf("Temp: %.2f°C\n",temp);
}

Here the output:
image

OK, well maybe when you find the bug in your terminal if will give you a clue about what the bug is in the Arduino IDE 2.x Serial Monitor. If so, please leave a comment here or on that bug report.

It is not only in Serial Monitor that I see this issue, it must be in the code somehow.
I get the same result when I generate a string to show in a browser.
image
from the line:

res += R"rawliteral( <text class="st3 st4" x="0" y="40" fill="beige" text-anchor="middle" dominant-baseline="middle">°C</text>
      </svg>)rawliteral";

Also I get it in part of the generated output:

<use href="[#segment](view-source:http://192.168.1.25/Temp#segment)" fill="rgb(93,255,0)" transform="rotate(-63)"/>
 <use href="[#segment](view-source:http://192.168.1.25/Temp#segment)" fill="rgb(97,255,0)" transform="rotate(-57)"/>
 <use href="[#segment](view-source:http://192.168.1.25/Temp#segment)" fill="Øü?" transform="rotate(-51)"/> <use href="[#segment](view-source:http://192.168.1.25/Temp#segment)" fill="Øü?" transform="rotate(-45)"/>
 <use href="[#segment](view-source:http://192.168.1.25/Temp#segment)" fill="Øü?" transform="rotate(-39)"/>
 <use href="[#segment](view-source:http://192.168.1.25/Temp#segment)" fill="Øü?" transform="rotate(-33)"/> 
<use href="[#segment](view-source:http://192.168.1.25/Temp#segment)" fill="Øü?" transform="rotate(-27)"/>
 <use href="[#segment](view-source:http://192.168.1.25/Temp#segment)" fill="Øü?" transform="rotate(-21)"/>
 <use href="[#segment](view-source:http://192.168.1.25/Temp#segment)" fill="Øü?" transform="rotate(-15)"/>
 <use href="[#segment](view-source:http://192.168.1.25/Temp#segment)" fill="Øü?" transform="rotate(-9)"/>
 <use href="[#segment](view-source:http://192.168.1.25/Temp#segment)" fill="rgb(20,20,20)" transform="rotate(-3)"/>

while the output I get from the function is correct but the received data is not
image

the lines showing "rgb(..."is generated by the following

 sprintf(temp,"rgb(%d,%d,%d)\0",r,g,b); 
    Serial.printf("%s,%d,%d,%d\n",temp,r,g,b);

the receiver prints: I: -63 Color:rgb(93,255,0) or I: -51 Color:���?
using following code:

Serial.printf("\t\t\tI: %d Color:%s\n\r",i,colour);

I solved both issues:

The first I replaced

res += R"rawliteral( <text class="st3 st4" x="0" y="40" fill="beige" text-anchor="middle" dominant-baseline="middle">°C</text>
      </svg>)rawliteral";

with:

res += "<text class=\"st3 st4\" x=\"0\" y=\"40\" fill=\"beige\" text-anchor=\"middle\" dominant-baseline=\"middle\">";
   res += units;
   res += "</text>";

for the second I do no longer "return" the value as a String but use char* passed by reference

this:

String SVGrainbow(byte value){
sprintf(temp,"rgb(%d,%d,%d)\0",r,g,b); 
return temp;
}

became

void SVGrainbow(char* retval, byte value){
.....
sprintf(temp,"rgb(%d,%d,%d)\0",r,g,b); 
strcpy(retval,temp);
}

I hope this isn't a red herring, but I just fixed a similar issue in my code that used snprintf():

      snprintf(&Tdata[0], sizeof(Tdata), "Servo %d pos=%d", servo, position);

by changing the Tdata[] declaration from a local variable to a global one.
I am surmising something else was overwriting the local data before I printed it using

      Serial.println(&Tdata[0]);

Interestingly, the gibberish was confined to the first 4 characters of my output.

Still seems to be an open issue!?

That is correct.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.