2017-04-20 667 views
0

我已将ESP8266 WiFi模块与Arduino UNO连接。引脚配置良好。我从串行监视器发送AT命令它响应正常,但当我发送AT + RST它不工作。ESP8266 AT响应正常,但无法复位

ððAT 


OK 
AT+RST 


OK 

ets Jan 8 2013,rst cause:2, boot mode:(3,7) 

load 0x40100000, len 1396, room 16 
tail 4 
chksum 0x89 
load 0x3ffe8000, len 776, room 4 
tail 4 
chksum 0xe8 
load 0x3ffe8308, len 540, room 4 
tail 8 
chksum 0xc0 
csum 0xc0 

2nd boot version : 1.4(b1) 
SPI Speed  : 40MHz 
SPI Mode  : QIO 
SPI Flash Size & Map: 8Mbit(512KB+512KB) 
jump to run user1 @ 1000 

ŒÃÕ�MEM CHECK FAIL!!! 
ärl�‚sò 
Ai-Thinker Technology Co. Ltd. 

invalid 

如何与Arduino的乌诺重置

+0

你是什么意思不工作?它显然重置自己。 –

+0

yes.gre_gor是对的。我认为Ans是因为他在最后得到'无效'而感到困惑 – Billa

+0

是的我最后在无效时感到困惑。但现在其工作 –

回答

1

全部为AT + RST首先返回ok您的硬件连接是perfect.But这可能是由于一些常见的bugs.Have在许多前来为我工作其次,是否有必须重置esp8266的原因?

代码:

#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 
    } 
} 

这段代码的目标很简单:以接收来自Arduino的串行窗口命令,将它们发送到ESP8266,并打印ESP8266的响应命令或其他行动(如接收HTTP请求)。

如果上面的代码段失败(发生在一些情况下),而(serial.available())码块使用以下段替换:

while(Serial.available()) // read the command character by character 
    { 
    // read one character from serial terminal 
    char ch = Serial.read(); 
    // send that one character to the esp8266 
    esp8266.print(ch); // send the read character to the esp8266 
    } 

注我下降字符串数据类型。

如果您想直接从阿尔杜伊诺到ESP8266发送命令,那么你应该使用下面的代码段:

使用此代码连接到ESP8266:

#include <SoftwareSerial.h> 

const byte rxPin = 2; // Wire this to Tx Pin of ESP8266 
const byte txPin = 3; // Wire this to Rx Pin of ESP8266 

// We'll use a software serial interface to connect to ESP8266 
SoftwareSerial ESP8266 (rxPin, txPin); 

void setup() { 
    Serial.begin(115200); 
    ESP8266.begin(115200); // Change this to the baudrate used by ESP8266 
    delay(1000); // Let the module self-initialize 
} 

void loop() { 
    Serial.println("Sending an AT command..."); 
    ESP8266.println("AT"); 
    delay(30); 
    while (ESP8266.available()){ 
    String inData = ESP8266.readStringUntil('\n'); 
    Serial.println("Got reponse from ESP8266: " + inData); 
    } 
} 

PS:不要忘了将串行结束的行设置为换行或回车。

在上面的代码段Iam只发送一个AT命令(ESP8266.println("AT");)进行演示。您可以用同样的方式发送任何命令。

+0

请接受它。 – Billa