首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ESP8266和Arduino接口

ESP8266和Arduino接口
EN

Stack Overflow用户
提问于 2015-06-09 20:06:59
回答 6查看 3.2K关注 0票数 3

我已经把阿杜伊诺和ESP8266联系起来了

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

我已使用1117电压调节器为ESP8266供电

当我最初购买ESp8266时,它运行正常,但现在它显示了无穷无尽的垃圾价值……

arduino是用以下代码编写的

代码语言:javascript
复制
#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
  }
}
EN

回答 6

Stack Overflow用户

发布于 2015-06-28 21:58:42

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

如果是115200,它将不能在softwareSerial的普通数字引脚上工作。

如果是较旧的电路板,则可以尝试更改为56000:

代码语言:javascript
复制
 esp8266.begin(56000); // your esp's baud rate might be different

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

代码语言:javascript
复制
 Serial.begin(115200);
票数 2
EN

Stack Overflow用户

发布于 2017-10-24 02:11:49

代码看起来没问题,但你应该看看你的ESP8266波特率可能不一样。检查以下内容:

  1. 单独检查ESP8266波特率,一旦你有了它,在你的Arduino模型中声明相同的波特率,一些克隆像nano one驱动的电压与原始的不同,
票数 1
EN

Stack Overflow用户

发布于 2017-11-20 18:16:10

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

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

代码语言:javascript
复制
Serial.begin(9600);

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30731584

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档