I connect my ESP to Arduino to my PC.
If I send AT commands from my serial monitor, I receive full response. I use 115200 and both NL & CR in my serial monitor.
ESP TX is connected to TX Arduino, same for RX.
The problem is when I try to send commands from my Arduino code. I don't receive any response. I use same 115200 both for serial and for ESP8266.
I user this code:
#include <SoftwareSerial.h>
SoftwareSerial esp8266(0,1);
void setup()
{
Serial.begin(115200);
esp8266.begin(115200);
}
void loop()
{
sendCommand("AT+GMR\r\n");
}
String sendCommand(String command, const int timeout, boolean debug)
{
String come = "";
while(esp8266.available())
{
char c = esp8266.read(); // read the next character.
Serial.write(c);
come += c;
}
Serial.println(come);
return come;
}
I can't see what is wrong here and why that works with just the Serial Monitor.
2 Answers 2
When you are using Arduino board just as USB --> RS232 converter then you have to, as you said, connect TX to TX and RX to RX. But when you want communication between microcontroler and ESP then you have to connect TX to RX and RX to TX. Here I explained that in details.
Make a choice:
- Are you using pins 0 and 1 for communicating with the PC, or
- Are you using pins 0 and 1 for communicating with the ESP8266?
You cannot do both.
Move the ESP8266 onto some other pins.
-
For esp8266 like in my code upCorneliu– Corneliu2016年10月22日 19:16:38 +00:00Commented Oct 22, 2016 at 19:16
-
@Corneliu then your Arduino cannot communicate with the PC, which means you will need to remove the Serial.xxx lines and find some other way of telling if your program works. That path is not recommended. Rather, move your ESP8266 to different pins.Chris Stratton– Chris Stratton2016年10月22日 19:18:19 +00:00Commented Oct 22, 2016 at 19:18
-
Ok. I move esp to pin 2 and 3; I set : ESP8266.begin(115200); And in my loop i have : ESP8266.println("AT\n"); And in my serial monitor i got : ƒÿCorneliu– Corneliu2016年10月22日 19:25:27 +00:00Commented Oct 22, 2016 at 19:25
-
Have you got it wired right? Your nominated TX pin through a voltage divider to ESP8266 RX, and ESP8266 TX to your nominated RX?Majenko– Majenko2016年10月22日 21:04:43 +00:00Commented Oct 22, 2016 at 21:04
-
Are you sure the baudrates of both devices (and serial monitor) are set right? If one is wrong, it's very likely to receive weird charactersaaa– aaa2016年12月05日 06:57:02 +00:00Commented Dec 5, 2016 at 6:57
TX to TX
andRX to RX
in certain cases can be correct. See my answer.