如何从连接到 arduino 的 ESP8266 获得 AT 响应 [英] how to get AT response from ESP8266 connected to arduino

查看:38
本文介绍了如何从连接到 arduino 的 ESP8266 获得 AT 响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ESP8266 wifi 模块并连接 arduino.将固件更新到最新版本后,我开始对 arduino 进行编程以获取从 wifi 传入的数据.我看到了很多关于通过 ESP8266 制作网络服务器的例子,但没有一个对我有用.

I am fighting with ESP8266 wifi module and connecting arduino. After updating firmware to newest version i started to programm arduino to get data incoming from wifi. I saw many examples about maiking webserver via ESP8266 but none of them works for me.

ESP 连接到我的 Arduino Leonardo:>

ESP is connected to my Arduino Leonardo: >

Arduino -> ESP8266

电源 3.3V -> vcc

power 3.3V -> vcc

地面 -> 地面

tx -> rx(通过逻辑电平转换器 5->3.3V)

tx -> rx (via logic level converter 5->3.3V)

rx -> tx(通过 logix 电平转换器

rx -> tx (via logix level converter

电源 3.3V ->gpio0(无任何电阻)

power 3.3V ->gpio0 (without any resistors)

我画了一个简单的草图:

I made simple sketch:

void setup(void){

  Serial.begin(9600);
  Serial1.begin(115200);

}

void loop() {
  if(Serial1.available())
  {
    Serial.println("WIFI IS AVAILABLE");
    Serial1.println("AT");
    delay(1000);
  } else {
    Serial.println("WIFI not available.");
    delay(1000);
  }
}

执行后,ESP8266 通电(红色 LED 亮起),并且每隔一秒蓝色 LED(闪烁)​​.这让我确信在 fakt 中AT"命令被传输到模块.但也有两个问题:

After executing it ESP8266 is powered (red led is on) and also every second blue led (blinks). That makes me sure that in fakt "AT" command is transmited to module. But there are also two issues:

  • 我想得到 esp 的回应——在这种情况下是OK"这个词.我试过 Serial1.read() 但它只读取一个字节.Serial1.readString() 使我的消息wifi 不可用"同时wifi 可用",好像有一段时间连接不可用

  • i want to get response from esp - in this case word "OK". I tried Serial1.read() but it only reads one byte. Serial1.readString() makes my messages "wifi not available" and sametimes "wifi is available" as if for a while the connection would be unavailable

在将草图上传到 arduino 并为 esp8266 wifi 模块供电后,它始终不可用 - 我需要关闭模块电源并再次打开以使其工作.

after uploading sketch to arduino and having powered esp8266 wifi module is always unavailable - i need to power the module off and on again to have it working.

有人可以帮我吗?

推荐答案

你需要做的是稍微改变你的方法.不要检查数据是否可用.诀窍是向模块发送一些东西,然后检查数据.

What you need to do is change your approach a bit. Do not check if data is available. The trick is to send the module something and then check for data.

做类似的事情:

while (Serial.available() > 0)
  Serial.read();

在您要发送的任何命令之前清除缓冲区.然后发送命令.然后检查数据作为响应.

to clear the buffer before any command you want to send. Then send the command. Then check for data as a response.

不要不要依赖该蓝色 LED 作为任何指示.这只是表明 ESP8266 正以某种方式忙于使用 WiFi,无论是执行保活、初始化 WiFi 还是其他任何方式.它可以与您发送的任何内容完全无关.如果您没有收到有效的回复,那么您必须假设您和模块之间存在通信问题.但有一件事是,如果蓝色 LED 永远不会熄灭,那么要么模块已冻结,要么固件已损坏.我有过很多次这样的经历.然后我重新加载固件,通常会修复它.它通常只发生在我重置、上传代码或更改线路的开发阶段.

Do not rely on that Blue LED as any indication. It is only an indication that the ESP8266 is busy using the WiFi in some sort of way, whether it is doing keepalives, initializing WiFi or whatever. It can be totally unrelated to whatever you are sending. If you do not receive a valid response then you must assume that there is comms issues between you and the module. One thing though is that if that Blue LED never goes off then either the module has frozen or the firmware was corrupted. I have had that many times. I then reload the firmware and usually that fixes it. It usually only happens during development times where I reset, upload code or change wires.

我在单独的自建板上使用我的 atmega328,而不是 Uno 上的那个,并在 3.3v 本身上运行该板,然后在该 atmega 板和我的 Uno 之间使用逻辑电平转换器,以便我可以编程它.但是我在非通信方面遇到过零星问题,但我怀疑这可能与电源有关.请注意,通过逻辑电平转换器运行串口也可能导致通信问题.

I use mine with an atmega328 on a separate slef-built board and not the one on the Uno and run that board on 3.3v itself and then use a logic level converter between that atmega board and my Uno so that I can program it. But I have had sporadic issues with non-comms but I suspect it might be power related. Be aware that running your Serial via the logic level converter might also be causing comms issues.

建议接线:除 RX、TX、VCC 和 GND 之外的所有引脚都通过 10K 上拉电阻连接到 VCC.RX 进入 arduino 的 TX,TX 进入 arduino 的 RX.你当然知道 VCC 和 GND 去哪里了.

Proposed wiring: All pins except RX,TX,VCC and GND goes to VCC via 10K pullup resistors. RX goes to the arduino's TX and TX goes to the arduino's RX. Of course you know where VCC and GND goes.

这篇关于如何从连接到 arduino 的 ESP8266 获得 AT 响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆