2015-02-24 70 views
3

我正在做一个简单的tcp通信,从arduino到树莓派pi与无线arduino上的ESP8266 wifi模块进行通信。tcp服务器运行在树莓派。我是能够在9600如何让AT命令在arduino中以编程方式在ESP8266 wifi模块中工作

AT+CIPMUX=1 
AT+CIPSTART=4,"TCP","192.168.43.150",7777 
AT+CIPSEND=4,5 
>hai 

如何做到这一点编程的一个Arduino sketch.I用在我的Arduino UNO下面的代码波特率做以下AT在Arduino的串口监视器命令TCP通信,但仍然没有任何成功。波特率仅为9600,因为它直接在串行监视器上工作。

#include <SoftwareSerial.h> 
SoftwareSerial esp8266(2,3); 

void setup() 
{ 
    Serial.begin(9600); 
    esp8266.begin(9600); // your esp's baud rate might be different 
} 

void loop() 
{ 
esp8266.println("AT"); 
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); 
    } 
} 
} 

的连接如下

ESP8266 Arduino Uno 

    Vcc  3.3V 
    CH_PD  3.3V 
    RX  RX(PIN 2) 
    TX  TX(PIN 3) 
    GND  GND 

回答

1

我也碰到过同样的问题,尚未找到了解决办法。 但是,您的连接有点儿,您必须将ESP8266模块的TX引脚连接到您的arduino的RX引脚,并将ESP8266模块的RX引脚连接到TX引脚。 希望这可以帮助你在你的路上

+0

现在有效。 Thankyou – 2015-03-10 09:08:32

4

这可能有点晚,但我最近还是遇到了类似的问题。如果它被排序,则可以随意忽略这一点。

根据ESP8266模块的固件版本,9600的波特率可能无法正常工作,请尝试使用115200--它可能证明更可靠?

我认为你上面的代码不起作用的主要原因是因为ESP在AT命令结束时需要换行符和回车符。串行监视器为您添加这些。而不是发送AT尝试发送AT\r\n。这应该鼓励ESP回复OK,或者如果回显开启AT\r\nOK

Serial.available()还检查接收缓冲区中是否有内容 - 这很遗憾,所以我不得不将delay(10)放在那里让它在缓冲区中注册一个字符。

#include <SoftwareSerial.h> 

//i find that putting them here makes it easier to 
//edit it when trying out new things 

#define RX_PIN 2 
#define TX_PIN 3 
#define ESP_BRATE 115200 

SoftwareSerial esp8266(RX_PIN, TX_PIN); 

void setup() 
{ 
    Serial.begin(9600); 
    esp8266.begin(ESP_BRATE); // I changed this 
} 

void loop() 
{ 
esp8266.println("AT\r\n"); //the newline and CR added 
delay(10); //arbitrary value 

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); 
    } 
} 
} 

我的下一个问题是,我的ESP的0回复是不可靠的 - 有时他们被读作确定,但有时他们是垃圾值。我怀疑这是模块电量不足的问题。

+0

我遇到了同样的问题,有时它会返回垃圾值。我解决了它增加了延迟句子的时间。对我来说,它和100一样好。所以,而不是'延迟(10);'我写了'delay(100)'让它在没有垃圾的情况下为所有命令工作。 – 2018-01-17 22:31:06

相关问题