ESP8266和Arduino接口

ESP8266和Arduino接口,arduino,arduino-uno,at-command,esp8266,Arduino,Arduino Uno,At Command,Esp8266,我已将Arduino与ESP8266连接到 Arduino针脚2连接到ESP的Tx Arduino针脚3通过分压器连接到ESP的Rx Arduino接地连接至ESP接地 Arduino 3v3连接至ESP的Chu PD 我使用1117电压调节器为ESP8266供电 当我最初购买ESp8266时,它工作正常,但现在它显示出源源不断的垃圾值 arduino使用以下代码编程 #include <SoftwareSerial.h> SoftwareSerial esp8266(2,3);

我已将Arduino与ESP8266连接到

Arduino针脚2连接到ESP的Tx Arduino针脚3通过分压器连接到ESP的Rx Arduino接地连接至ESP接地 Arduino 3v3连接至ESP的Chu 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
  }
}
#包括
软件系列esp8266(2,3);//使RX Arduino线路为引脚2,使TX Arduino线路为引脚3。
//这意味着您需要将发送线路从esp连接到Arduino的针脚2
//以及从esp到Arduino引脚3的RX线路
无效设置()
{
Serial.begin(9600);
esp8266.begin(9600);//您的esp的波特率可能不同
}
void循环()
{
if(esp8266.available())//检查esp是否正在发送消息
{
而(esp8266.available())
{
//esp有数据,因此将其输出显示到串行窗口
char c=esp8266.read();//读取下一个字符。
串行写入(c);
}  
}
if(Serial.available())
{
//需要以下延迟,否则arduino将读取命令的第一个字母,而不是其余字母
//换句话说,如果您使用AT+RST,则不会延迟,例如,Arduino将读取字母A并发送它,然后读取其余字母并发送它
//但我们想同时发送所有信息。
延迟(1000);
String命令=”;
while(Serial.available())//逐个字符读取命令
{
//读一个字符
command+=(char)Serial.read();
}
println(命令);//将读取的字符发送到esp8266
}
}

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

如果115200,它将无法在softwareSerial的正常数字管脚上工作

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

 esp8266.begin(56000); // your esp's baud rate might be different
否则,您需要将esp8266连接到硬件试用端口

 Serial.begin(115200);

代码似乎还可以,但您应该检查您的ESP8266波特率可能不同。签出以下内容:

  • 单独检查ESP8266波特率,一旦有了它,请声明相同的波特率 将波特率输入Arduino

  • 检查您的Arduino型号,一些克隆产品,如nano one驱动器 与原来的电压不同


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

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

    Serial.begin(9600);
    
    您将在显示器上获得响应,并尝试通过将3.3v连接到RST引脚1-2秒来重置wifi模块。
    希望有帮助。

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

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

    你确定这是
    C
    ?你不知道吗?Arduino语言只是一组C/C++函数,可以从你的代码中调用。。。访问:了解更多信息information@AngryBird在这里,没有所谓的“C/C++”语言。阿杜伊诺比C.@灰熊更像C++,那又怎么样?我不明白这是如何使这个特殊代码对
    c
    标记有效的。发送数据的esp8266代码看起来如何?我使用esp-01的SoftwareSerial,使用9600波特没有问题。