Y
Y
Yaroslav2021-01-12 17:08:48
Arduino
Yaroslav, 2021-01-12 17:08:48

ESP8266 (ESP-01) does not listen to Arduino. What to do?

I'm trying to connect Arduino Mega and ESP8266 (ESP-01). For example, I took a simple ping program that listens to two ports (one USB-Arduino port, the second Arduino-ESP port), and duplicates information from them to each other. Here is the program itself:

#include <SoftwareSerial.h>
#define RX 19
#define TX 18

SoftwareSerial esp8266(RX, TX);

void setup() {
  Serial.begin(115200);
  esp8266.begin(115200);
}

void loop() {
  if (esp8266.available()) {
    Serial.write(esp8266.read());
  }

  if (Serial.available()) {
    esp8266.write(Serial.read());
  }
}


There are no problems in the firmware, the module works correctly (responds to AT commands if sent directly). There should be no problems with the wiring diagram either, because. after flashing the module, I didn’t change it (only removed the ground from RESET to Arduino and rearranged RX and TX to Arduino coming from ESP (now RX-TX and TX-RX, where RX and TX Arduino correspond to the pins indicated in the program)). Also, the speed of the module is exactly 115200, and when sending data, it costs NL & CR.

Moreover, when sending something from Arduino using the above program, the RX LED lights up on the board itself, and blue lights up on the module, i.e. the data seems to be being transferred.

PS Even when the module itself is rebooted, nothing is output to the USB port.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Y
Yaroslav, 2021-01-12
@YaroslavHub

As a result, I solved the problem differently: instead of declaring a software UART through SoftwareSerial, I used an already existing hardware Serial1 (the same pins that I tried to use in the original program). To be honest, I still do not understand why one works and the other does not, when the result should be the same (I mean the result of declaring Serial1 and declaring via SoftwareSerial, using the same pins). If anyone knows, please tell me.
The working code looks like this:

#define esp Serial1
 
void setup()
{
  Serial.begin(9600);
  esp.begin(115200);
}
 
void loop()
{
  if (esp.available()) {
    Serial.write(esp.read());
  }
  if (Serial.available()) {
    esp.write(Serial.read());
  }
}

PS The original version does not work, even if I change the ESP speed to 9600, as the other answerers suggested.

A
Armenian Radio, 2021-01-12
@gbg

Speeds and bit/parity must match on both devices.
And we must take into account that the arduins IO work at 5 volts, and for ESP - at 3.3, coordination is needed.

B
BakaTopcat, 2021-01-12
@BakaTopcat

SoftwareSerial works disgustingly on 115200, in fact it sends and receives garbage. With SoftwareSerial, I managed to make ESP-01 friends only on 38400. There is an AltSoftSerial library, it more or less rose to 57600.
In order to switch ESP, you need to enter the AT command: AT+UART_DEF=38400,8,1,0,0
Do not forget about matching the levels of logic and power, simply connecting the ESP to the Arduino will burn the ESP.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question