乐鑫技术交流
直播中

刘杰

7年用户 1292经验值
私信 关注
[问答]

ESP8266获取到奇怪的字符是为什么?如何解决?

所以我开始使用 ESP8266,这是一段艰难的旅程。每当我认为自己拥有时,它都会失败。我做的最后一件事是安装新固件,突然间我得到了正常的单词和奇怪的字符。
我的代码:
代码:全选#include
#include

SoftwareSerial esp(2, 3); // RX, TX

void setup()
{
  Serial.begin(9600);
  esp.begin(115200);
  connectoToWifi();
}

void connectoToWifi()
{
  String SSIDstring = ("\"WIFI_NAME_HERE\"");
  String PASSstring = ("\"WIFI_PASSWORD_HERE\"");
  
  sendData("AT+RST\r\n", 1000, true);
  sendData("AT+CWMODE=1\r\n", 500, true);
  sendData("AT+CWJAP=" + SSIDstring + "," + PASSstring + "\r\n", 5000, true);
  sendData("AT+CIPSTATUS\r\n", 500, true);
  sendData("AT+CIFSR\r\n", 500, true);
  sendData("AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",80\"", 500, true);
}

String sendData(String command, const int timeout, boolean debug)
{
  String response = "";
  esp.print(command); // Stuur een "lees" karakter naar de ESP.
  long int time = millis();
  while ((time + timeout) > millis())
  {
    while (esp.available())
    {                  
      char c = esp.read(); // Lees het volgende karakter.
      response += c;
    }
  }

  if (debug)
  {
    Serial.println(response);
  }
  return response;
}

void loop()
{
  
}


在我的串行监视器中,我看到类似这样的内容:
我还尝试了其他 30 条建议,但似乎都没有用。一些不断回来的:- 闪烁它(做了 6 次)- 改变 esp 的波特率(非常受欢迎)- 检查连接- 重置它,闪烁它,改变波特率我在这里错过了什么?

回帖(1)

李丽

2024-5-22 17:52:59
ot;);  String cmd = "AT+CWJAP=" + SSIDstring + "," + PASSstring + "rn";  esp.print(cmd);  delay(5000); // wait for connection}void loop(){  if(esp.available()) {    String response = esp.readString();    Serial.println(response);  }}

这个问题可能是由于ESP8266与串口通信时的波特率不匹配引起的。确认你的ESP8266波特率与代码中的波特率匹配。如果还是不行,尝试更新固件或使用其他的串口库。同时需要确保电源稳定,ESP8266的供电电压在3.3V左右,过高或过低都可能导致奇怪的字符出现。
举报

更多回帖

发帖
×
20
完善资料,
赚取积分