2015-06-09 112 views
0

我已连接的Arduino与ESP8266与ESP8266和Arduino的接口

连接到经由分压器 Arduino的GND连接到ESP的连接到ESP的CH_PD GND Arduino的3v3中连接到ESP的的Rx ESP的的Tx Arduino的销3

Arduino的销2

我一直在使用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 
    } 
} 
+2

你确定这是'C'吗? –

+0

难道你不知道吗?Arduino语言仅仅是一套C/C++函数,可以从你的代码中调用...访问:http://www.arduino.cc/en/Main/FAQ了解更多信息 – AngryBird

+3

@AngryBird在这里,没有一种叫做“C/C++”的语言。 Arduino比C的C++更多。 – unwind

回答

1

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

如果115200不支持softwareSerial的普通数字引脚。

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

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

否则,你将需要挂钩的esp8266到HardwareSerial端口

Serial.begin(115200); 
1

的代码似乎是好的,但你应该检查你的ESP8266波特率可能不同。结帐以下内容:

  1. 检查ESP8266波特率独自一人,一旦你拥有了它,声明相同 波特率到您的Arduino。

  2. Checkout的Arduino的模型,一些克隆像纳米一个驱动 不同的电压比原来的一个,

0

上传的代码,并检查串行监控与特定波特率任何回应,如果你没有得到任何特定波特率的响应,然后改变波特率直到得到响应。 对于少数模块,默认波特率为57600.So根据它进行检查。

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

Serial.begin(9600); 

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

+0

如果可能,请添加一些代码示例 – Maddy

0

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

0

检出逻辑值,因为esp8266在3.3v和串口波特率上工作。在少数情况下,ESP8266可能有内部故障并产生垃圾值。至于ESP8266而言,结帐here 它帮了我很多