WiFiManager.autoConnect garbled code problem

#include <WiFiManager.h>

void setup() {
  Serial.begin(115200);
  WiFiManager wifiManager;
  wifiManager.setDebugOutput(true);
  wifiManager.autoConnect("AutoConnectAP","12345678");
}

void loop() {
  Serial.println("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
}

  • Serial port output content:
    18:39:40.970 -> ABCDEFGHIJKLMNOPQRSTUVWXYZ
    18:39:40.970 -> ABCDEFGHIJKLMNOPQRSTUVWX
    18:39:40.970 -> ABCDEFGHIJLMNOPQRSTUVWXYZ
    18:39:40.970 -> ABCDEFGHIJKLMNOPQRSTUVWXYZ

Does the same loop() code print correctly if you comment out the WiFi stuff like this?

// #include <WiFiManager.h>

void setup() {
  Serial.begin(115200);
  // WiFiManager wifiManager;
  // wifiManager.setDebugOutput(true);
  // wifiManager.autoConnect("AutoConnectAP","12345678");
}

void loop() {
  Serial.println("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
}

Either way, you could try adding a delay() like this:

void loop() {
  Serial.println("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
  delay(100);
}
#include <WiFiManager.h>


void setup() {
  Serial.begin(115200);  // 设置串口通信波特率为 9600
  WiFi.mode(WIFI_STA);
  WiFiManager wifiManager;
  
  wifiManager.setDebugOutput(false);
//  wifiManager.autoConnect("AutoConnectAP","12345678");  //创建一个模拟wifi,使用密码登录
}

/*每隔5秒输出一次内存信息*/
void loop() {
  Serial.println("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
}

If I write it like this, there is no problem and the content can be output normally, but I can't comment it because it is used to configure the network. I don't understand how to avoid this error.

Adding a small delay will slow down the loop and may prevent truncation due to overwhelming the serial buffer. For example:

void loop() {
  Serial.println("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
  delay(500);  // Add a delay to stabilize the Serial output
}

I tried several methods, but none of them could solve my problem.

void loop() {
  Serial.println("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
  delay(500);  // Add a delay to stabilize the Serial output
}
void loop() {
  Serial.println("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
  delay(100);  // Add a delay to stabilize the Serial output
}
void loop() {
  Serial.println("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
  Serial.flush();
}
  • The problem is that this line of code wifiManager.autoConnect("AutoConnectAP","12345678");
    It outputs garbled characters, and I haven't found a solution yet

Do you mean that some of the characters A to Z are missing, and there are no additional unpexpected characters? I.E. as shown in post #1.
There's a big difference between just missing characters and seeing extra unexpected characters. If it's just missing characters then something isn't giving the Serial code enough time to transmit all the characters.
Serial.println() returns the number of characters printed. You could check its return value to see if the characters are not being accepted for transmission because the transmit buffer is full.

As a matter of curiosity, what hardware are you using here?

  • This is my test data. It doesn't seem like the buffer is full because there are still 100 left, but the output is garbled or missing characters.

I don't have any more suggestions at the moment. If I think of something I'll post it.

#include <WiFiManager.h>

void setup() {
  Serial.begin(115200);
  WiFiManager wifiManager;
  wifiManager.setDebugOutput(true);
  wifiManager.autoConnect("AutoConnectAP","12345678");
}

void loop() {
  
  int serialAvailableForWrite = Serial.availableForWrite(); //可用缓冲区字节
  uint32_t freeHeap = ESP.getFreeHeap(); //可用内存
  if (serialAvailableForWrite < 50) {  // 如果缓冲区空间小于10字节
    while (Serial.available() > 0) {
      Serial.read();
    }
  }else{
    Serial.print("H: ");Serial.print(serialAvailableForWrite);Serial.print(" - ABCDEFGHIJKLMNOPQRSTUVWXYZ");Serial.print(" - memory: ");Serial.println(freeHeap);
  }
}

Write like this