-1

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.

4
  • 3
    Where is the godsbedamned website which is telling people to use SoftwareSerial on pins 1 and 0 so I can wipe it of the face of the earth?!?!
    – Majenko
    Oct 22, 2016 at 19:00
  • You connected Tx>Tx and Rx<Rx. You have no V dividers. HOW DOES IT WORK?!?!?!?! (me confused af) please post a picture of your circuit
    – Dat Ha
    Oct 22, 2016 at 19:02
  • @Majenko a search for "SoftwareSerial esp8266(0,1);" shows it literally everywhere. I'm generally negative on the canonical question idea, but that and duplicate closes might be warranted. Oct 22, 2016 at 19:15
  • @Dat Ha - Yes, TX to TX and RX to RX in certain cases can be correct. See my answer.
    – Chupo_cro
    Dec 5, 2016 at 20:38

2 Answers 2

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.

1

Make a choice:

  1. Are you using pins 0 and 1 for communicating with the PC, or
  2. Are you using pins 0 and 1 for communicating with the ESP8266?

You cannot do both.

Move the ESP8266 onto some other pins.

5
  • For esp8266 like in my code up
    – Corneliu
    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. 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
    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
    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 characters
    – Paul
    Dec 5, 2016 at 6:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.