[SOLVED] Serial Monitor shows bad characters

Hi;
I have a ESP8266 Wi-Fi module( here is its picture ).
I want to upload and program this code on it using arduino version 1.6.9:

void setup()
{
  Serial.begin(9600);
  Serial.write("Hello World");
}

void loop()
{
}

but when i upload on it i get bad characters on serial monitor ( here is the picture of bad chars ) i try other baud rates but not working.My settings are here

Do Serial.print or Serial.println (if you want to go to next line after printing) instead of write.

J-M-L:
Do Serial.print or Serial.println (if you want to go to next line after printing) instead of write.

https://i.imgsafe.org/48d5d7f1ae.png is new code and the problem is exist :frowning:

Welcome to the forum.
What happens, when you turn serial monitor off and switch it on again via the IDE after the sketch is running?

Maybe you have to insert a code line which waits a very little time before the serial monitor has to display something, which is e.g. required for the Leonardo.

void setup()
{
  Serial.begin(9600);
  while (! Serial);
  Serial.print("Hello World");
}

void loop()
{
}

https://i.imgsafe.org/48d5d7f1ae.png is new code

Please: always post your code in </> brackets - you will lose a lot of readers, posting code as an image link.

During boot of the ESP8266 (before the welcome message is displayed) the baud rate is set to 76800 before being set to the default baud rate of your firmware (note I do not know what firmware you are running, there are many floating about right now). This is normal! You will know if your ESP8266 has successfully booted if you receive a welcome message (which varies with firmware).

From:

Post #5: makes sense.
As I don't have an ESP8266 currently at hand: it would be interesting, if the code line for the Leonardo which waits for the serial monitor being ready, or a short delay until all power and boot conditions are stabile, would eliminate the garbage.

So I am waiting for the PO coming back with an answer if he was successful with one of these approaches.

rpt007:
Post #5: makes sense.
As I don't have an ESP8266 currently at hand: it would be interesting, if the code line for the Leonardo which waits for the serial monitor being ready, or a short delay until all power and boot conditions are stabile, would eliminate the garbage.

So I am waiting for the PO coming back with an answer if he was successful with one of these approaches.

thanks for your help.I try your code:

void setup()
{
  Serial.begin(9600);
  while (! Serial);
  Serial.print("Hello World");
}

void loop()
{
}

and now on the serail monitor i get this:

0‚~?–4“Ò¶£ÿ_SAEþûHello World

And i should say that i try many soloutions in the stackoverflow but none of them solved my problem.

Well there might be garbage in your serial line during startup . Is that a problem?

Just print a couple white lines at the beginning or your code...

If you plan to replace later on the terminal display by a device, then plan to send something recognizable as the start of the good communication

J-M-L:
Well there might be garbage in your serial line during startup . Is that a problem?

Just print a couple white lines at the beginning or your code...

If you plan to replace later on the terminal display by a device, then plan to send something recognizable as the start of the good communication

Yes my problem is that before printing my data, it prints some bad chars and then printing my data, how can i prevent from printing those bad chars?

rpt007:
Post #5: makes sense.
As I don't have an ESP8266 currently at hand: it would be interesting, if the code line for the Leonardo which waits for the serial monitor being ready, or a short delay until all power and boot conditions are stabile, would eliminate the garbage.

So I am waiting for the PO coming back with an answer if he was successful with one of these approaches.

I changed my code to:

void setup()
{
  Serial.begin(9600);
  while (! Serial);
  Serial1.println("Hi My Name is Emad ");
}

void loop()
{
}

and again the output is:

0‚~?–4“Ò¶£ÿOCAEþû

You can't prevent it form printing those bad characters. The module prints that as a part of its internally programed boot sequence. You would have to change the bootloader. Why is it such a problem, anyway? If you are sending serial data to a PC program, you would frame the data so that garbage is ignored as suggested by J-M-L.

rpt007:
Welcome to the forum.
What happens, when you turn serial monitor off and switch it on again via the IDE after the sketch is running?

Maybe you have to insert a code line which waits a very little time before the serial monitor has to display something, which is e.g. required for the Leonardo.

void setup()

{
  Serial.begin(9600);
  while (! Serial);
  Serial.print("Hello World");
}

void loop()
{
}

Thanks Dear, this was the correct answer :slight_smile:

Congratulations!

To help others with the same problem:

What exactly did the trick:

  1. the inserted line with the while statement or
  2. switching serial monitor ON and OFF ?

SedEmadHelmi:
I changed my code to:

void setup()

{
  Serial.begin(9600);
  while (! Serial);
  Serial1.println("Hi My Name is Emad ");
}



...

You've initialized Serial object and trying to printlt from Serial1 object.[/code]

@NStorm:

look at reply#12 where the PO posted the corrected code which apparently worked.