3

我已将 Arduino 与 ESP8266 连接到

Arduino 引脚 2 连接到 ESP 的 Tx Arduino 引脚 3 通过分压器连接到 ESP 的 Rx Arduino GND 连接到 ESP 的 GND Arduino 3v3 连接到 ESP 的 CH_PD

我使用 1117 稳压器为 ESP8266 供电

当我最初购买 ESp8266 时它可以工作,但现在它显示出无穷无尽的垃圾值......

arduino 使用以下代码进行编程

#include <SoftwareSerial.h>

SoftwareSerial esp8266(2,3); // make RX Arduino line is pin 2, make TX Arduino line is pin 3.
                             // This means that you need to connect the TX line from the esp to the Arduino's pin 2
                             // and the RX line from the esp to the Arduino's pin 3
void setup()
{
  Serial.begin(9600);
  esp8266.begin(9600); // your esp's baud rate might be different
}

void loop()
{
  if(esp8266.available()) // check if the esp is sending a message 
  {
    while(esp8266.available())
    {
      // The esp has data so display its output to the serial window 
      char c = esp8266.read(); // read the next character.
      Serial.write(c);
    }  
  }



  if(Serial.available())
  {
    // the following delay is required because otherwise the arduino will read the first letter of the command but not the rest
    // In other words without the delay if you use AT+RST, for example, the Arduino will read the letter A send it, then read the rest and send it
    // but we want to send everything at the same time.
    delay(1000); 

    String command="";

    while(Serial.available()) // read the command character by character
    {
        // read one character
      command+=(char)Serial.read();
    }
    esp8266.println(command); // send the read character to the esp8266
  }
}
4

6 回答 6

2

您的 esp8266 可能以 56000 或 115200 波特率而不是 9600 工作。这会导致垃圾被读取。

如果是 115200,它将无法在带有软件串行的普通数字引脚上工作。

如果是旧板,那么您可以尝试更改为 56000:-

 esp8266.begin(56000); // your esp's baud rate might be different

否则,您需要将 esp8266 连接到 HardwareSerial 端口

 Serial.begin(115200);
于 2015-06-28T13:58:41.587 回答
1

代码似乎没问题,但你应该检查你的 ESP8266 波特率可能不同。检查以下内容:

  1. 单独检查 ESP8266 波特率,一旦你有了它,在你的 Arduino 中声明相同的波特率。

  2. 检查您的 Arduino 模型,一些克隆(如 nano one)驱动的电压与原始模型不同,

于 2017-10-23T18:11:49.497 回答
0

检查逻辑值,因为 esp8266 在 3.3v 和串口波特率下工作。在少数情况下,ESP8266 可能会出现内部故障并产生垃圾值。就 ESP8266 而言,在这里结帐 它对我帮助很大

于 2017-12-17T09:06:02.123 回答
0

作为其他答案的补充,尝试用逻辑电平转换器替换分压器,因为 esp 具有 3.3v 逻辑和 arduino 5v 逻辑。

于 2017-11-28T18:12:57.720 回答
0

上传代码并检查串行监视器是否有任何具有特定波特率的响应,如果您在特定波特率上没有得到任何响应,则更改波特率直到得到响应。对于少数模块,默认波特率将是 57600。因此请根据它进行检查。

您可以使用上面给定的代码并更改波特率以esp8266.begin(56000); 更改波特率,例如 9600、56000、112500 等,并以 9600 波特率检查串行监视器。

Serial.begin(9600);

您将在显示器上得到响应,并尝试通过将 3.3v 连接到 RST 引脚 1-2 秒来重置 wifi 模块。希望能帮助到你。

于 2017-11-20T10:16:09.770 回答
0

移除 Arduino TX 到 NodeMCU Rx 引脚之间的分压器和串联 330ohm 谢谢

于 2021-09-21T16:22:37.577 回答