Bad Characters in serial monitor output

Ted,

I found a resolution.

I posted my findings on the WiFi issues thread @ ESP8266 NodeMCU WiFi issues - Programming Questions - Arduino Forum post # 13.

I had to change my crystal frequency by adding a flag to the firmware build in boards.txt. The fact that the firmware for this particular board does not do that automatically is incredible.

Here's the complete steps for those who wish to apply the fix:

Note- this is for my HiLetgo NodeMCU ESP8266 board. The fix will only work if your board actually runs @ 40 MHz. Also note that all of these steps assume you are using a Windows PC. If you are on another system, you'll have to adapt the steps for you, though it shouldn't be too difficult to do.

If you want to be certain as to what frequency your board operates at, follow these steps:

  1. Go here(Tools | Espressif Systems) and download the file called "Flash Download Tools (ESP8266 & ESP32)".

  2. Extract the .rar file, and browse in the resulting folder to find 'ESPFlashDownloadTool_v3.6.3.exe' and run it.

  3. Choose the top option in the popup window that says 'ESP8266 Download Tool'.

  4. At the top of the resulting window will be a table with empty values. Make sure none of the rows are checked. The idea is to flash nothing to your device.

  5. At the bottom right part of the window, select the correct COM port for your board. Mine was COM3.

  6. Hit start. After a moment the DETECT INFO box will populate with information. Among this information is something like 'crystal: 40 Mhz'. This is your crystal frequency.

  7. Close the tool.

Here are the steps to configure the Arduino IDE to the correct crystal rate:

  1. Browse to the AppData folder for Arduino IDE. This is located at C:\Users\YourUser\AppData\Local\Arduino15\

  2. Open the 'packages folder, then the esp8266 folder, then hardware, then esp8266, then the folder named after the current version (mine was 2.4.0-rc2). The total address for this is:

C:\Users\YourUser\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc2\

  1. Open boards.txt with your favorite text file editor. use ctrl+f to find the board you're using in the Arduino IDE. For me it was the line 'nodemcuv2.name=NodeMCU 1.0 (ESP-12E Module)', so searching for NodeMCU 1.0 did the trick.

  2. You should be looking at the section of text lines that start with the name of your board, for me it's nodemcuv2. Add an extra line somewhere in this section that starts with the name of your board, then complete it in the following manner:

nodemcuv2.build.extra_flags=-DF_CRYSTAL=40000000 (use 26000000 if that's what your crystal is)

Make sure to replace nodemcuv2 with the name of your board as is used in the section you're in.

  1. Save the .txt file, exit your editor. Restart your Arduino IDE.

  2. Send a test sketch to your board. Here's a simple one to test serial output:

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

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println("test");
  delay(2000);
}

If this works then your crystal frequency is set correctly. You can further test this by running the example blink sketch which is at (in the Arduino IDE) File -> Examples -> ESP8266 -> Blink. While running this sketch, count the seconds between blinks- if it seems like 2 seconds, then you're probably good to go.

Note that you'll probably have to redo this procedure for each update your board has when downloaded from the boards manager in the IDE, since it'll probably completely replace that section of the .txt file.

I hope this is helpful to others out there who were stuck on this issue.

Thank you Ted for your continued help and support, and for the other helpers in the other thread I had @ ESP8266 NodeMCU WiFi issues - Programming Questions - Arduino Forum.

1 Like