1

I was trying to connect my Arduino Nano to my home Wi-Fi. To do that, I connected my Arduino to ESP8266 module.

I connected pins

Arduino  | ESP8266
3.3V     | VCC
3.3V     | CH_PD
D10      | RXD
D11      | TXD
GND      | GND

to connect to Wi-Fi, I used code which I found on internet.

What I'm getting is "FAILED - Timeout exceeded" which indicates there is no response from the ESP module. Is it possible I did something wrong and I fried it, or I connected it wrong? Or maybe it does not have enough power (I'm powering my Arduino via computer USB port)? I also read reviews which indicates customers who bought similar product from different vendors they had issues with firmware. Is it possible I have same problem?

Code

#include <SoftwareSerial.h>
SoftwareSerial softSerial(10, 11); // RX, TX
String WSSID = "xxxxxxxxxxxx";
String WPASS = "xxxxxxxxxxxx";
bool r;

void setup() {
  /* SETUP SERIAL COMMUNICATION */
  espSerialSetup();
  delay(2000); // Without this delay, sometimes, the program will not start until Serial Monitor is connected
  r = espSendCommand( "AT+CIFSR" , "OK" , 5000 );
  if( !r ) {
    r = espSendCommand( "AT+CWMODE=1" , "OK" , 5000 );
    r = espSendCommand( "AT+CWJAP=\""+WSSID+"\",\""+WPASS+"\"" , "OK" , 15000 );
  }
}

void loop(){    
  r = espSendCommand( "AT+CIPSTART=\"TCP\",\"108.59.11.102\",80" , "OK" , 5000 );
  String getRequest = "GET /shiznic/ HTTP/1.1\r\nHost: www.rootpower.com\r\n";
  int getRequestLength = getRequest.length() + 2; // add 2 because \r\n will be appended by SoftwareSerial.println().
  r = espSendCommand( "AT+CIPSEND=" + String(getRequestLength) , "OK" , 5000 );
  r = espSendCommand( getRequest , "+IPD" , 15000 );
  //r = espSendCommand( getRequest , "world" , 15000 ); // page should respond with Hello, world.
  if( !r ) {
    Serial.println( "Something wrong...Attempting reset...");
    espSendCommand( "AT+RST" , "ready" , 20000);
    espSendCommand( "AT+CWMODE=1" , "OK" , 5000 );
    espSendCommand( "AT+CWJAP=\""+WSSID+"\",\""+WPASS+"\"" , "OK" , 15000 );
  }    
  delay(3000);   
}

void espSerialSetup() {

  // change baud rate so SoftwareSerial works better -- need a certain version of ESP for this to work and be retained after power cycle
  // make sure Serial Monitor port speed is set to 9600
  softSerial.begin(115200); // default baud rate for ESP8266
  delay(1000);
  softSerial.println("AT+CIOBAUD=9600");
  delay(1000);
  softSerial.begin(9600);
  Serial.begin(9600);  
}

bool espSendCommand(String cmd, String goodResponse, unsigned long timeout) {
  Serial.println("espSendCommand( " + cmd + " , " + goodResponse + " , " + String(timeout) + " )" );
  softSerial.println(cmd);
  unsigned long tnow = millis();
  unsigned long tstart = millis();
  unsigned long execTime = 0;
  String response = "";
  char c;
  while( true ) {
    if( tnow > tstart + timeout ) {
      Serial.println("espSendCommand: FAILED - Timeout exceeded " + String(timeout) + " seconds" );
      if( response.length() > 0 ) {
        Serial.println("espSendCommand: RESPONSE:");
        Serial.println( response );
      } else {
        Serial.println("espSendCommand: NO RESPONSE");
      }
      return false;
    }
    c = softSerial.read();
    if( c >= 0 ) {
      response += String(c);
      if( response.indexOf(goodResponse) >= 0 ) {

        execTime = ( millis() - tstart );
        Serial.println("espSendCommand: SUCCESS - Response time: " + String(execTime) + "ms");
        Serial.println("espSendCommand: RESPONSE:");
        Serial.println(response);
        while(softSerial.available() > 0) {
          Serial.write(softSerial.read());
        }
        return true;
      }
    }
    tnow = millis();
  }
}

UPDATE I changed connections to D11 | RXD D10 | TXD

and i also simplified my code

#include <SoftwareSerial.h>

SoftwareSerial esp(10, 11);

void setup() {
   Serial.begin(115200);
  while (!Serial);
  Serial.println("Started");
  esp.begin(115200);
  esp.write("AT\r\n");
}

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

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

now I'm sending basic AT command to test connection, and still not getting any response. LED on ESP module is on, so I'm assuming it is working.

user902383
  • 123
  • 1
  • 7

2 Answers2

3

By the looks of the information you have provided, it looks as though you have not made the crossed serial connection: rx-tx tx-rx.

Your wiring:

Arduino  | ESP8266
3.3V     | VCC
3.3V     | CH_PD
D10      | RXD
D11      | TXD
GND      | GND

And when you intialize the software serial library:

SoftwareSerial softSerial(10, 11); // RX, TX

You declare D10 as RX and then connect it to the ESPs RX and ditto for the TX line.

What you need to do is the following:

Arduino  | ESP8266
3.3V     | VCC
3.3V     | CH_PD
D10      | TXD   //change to this
D11      | RXD   //change to this
GND      | GND

Also you need to ensure that the arduino TX line does not exceed 3.3V you can use a voltage divider, logic-level shifter board or a 74LVC245. This is important as the 5V arduino pins will damage a 3.3V device. This is a note as arduino nano is a 5V device from what I know(I may be corrected).

RSM
  • 1,457
  • 1
  • 11
  • 26
2

As far as I know, the 3.3v on the Arduino board might not have enough current for the ESP module, as it is very 'power hungry'.

I've had some hard time making my modules work properly, and your problem could be a number of things.

I will stick to Ockam's razor principle and go by the simple side.

In your code you are using 9600 baud,but the ESP8266 'base' speed is 115200. Try that speed (and CR+LF) also on your Usb cable and it might work.