1

I am new to arduino and am trying to connect the esp8266 to arduino UNO and send commands to the arduino using an android phone. I have double, triple checked the connections and I am sure they are 100% correct. I have connected esp GND to arduino GND, esp VCC to arduino 5V, esp TX to arduino SoftwareSerial RX and esp RX to arduino SerialSoftware TX and CH_PD to 5V. I can connect to esp using my phone but I can't send commands to it. I am using TCP/UDP Terminal on android to test the connection. Phone is connected to the AP but in the app it is not. I configured the app with 192.168.4.1 IP and 333 Port and I know that app works correctly because I have tested its integrity several times before. I have searched so much and tried so many but non worked.

My code:

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

boolean FAIL_8266 = false;

#define BUFFER_SIZE 128
char buffer[BUFFER_SIZE];

void setup() {

  Serial.begin(9600); 
  ESP8266.begin(115200);  // change this value to your wifi module (esp8266) baud rate

  do{
  ESP8266.println("AT");
    delay(1000);
    if(ESP8266.find((char*)"OK"))
    {
      Serial.println("Module is ready");
      delay(1000);

      //configure ESP as AP 
      Serial.println("AT+CWMODE=2");
      delay(1000);

      //Set multi connections
      Serial.println("AT+CIPMUX=1");
      delay(1000);

      Serial.println("Server setup finish");
      delay(1000);

      FAIL_8266 = false;

    }
    else{
      Serial.println("Module have no response.");
      delay(500);
      FAIL_8266 = true;
    }
  }while(FAIL_8266);

  ESP8266.setTimeout(100); 

}

void loop() {

  if(ESP8266.available()){
    String msg = ESP8266.readString();
    Serial.println("MSG: "+msg);
  }
}

Could anyone please tell me what is wrong?

5
  • You can't use SoftwareSerial reliably at 115200 baud. The Arduino just can't keep up with the speed to the data coming in. That said, you should write a simple serial echo program to allow you to communicate with the esp8266 manually via the Arduino to test that communication is actually happening. Commented Aug 20, 2019 at 10:13
  • @Majenko Thanks about the answer, I did a little research about what you said on the internet and it looks correct. I have read about changing the esp8266 baudrate to a lower amount but I didn't do it because many have reported that doing it have bricked their esp8266. Now, do you have anything in mind to fix the problem? Commented Aug 20, 2019 at 18:17
  • You really want to reduce the ESP8266 baud rate. You should get yourself set up for reflashing the ESP8266 first though. It's something you should get into anyway - it's far more efficient writing software to run directly on the ESP8266 rather than struggling with a ropey AT command set. Commented Aug 20, 2019 at 18:40
  • @Majenko I flashed my esp8266 and now it is working. Thanks for the Assist. Commented Aug 21, 2019 at 9:35
  • it's virtually impossible to brick an esp; all you need to do is put it in flash mode and reflash. Commented Aug 21, 2019 at 17:10

0

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.