0

I am working on esp8266 module with arduino uno board. This is my program.

#include <SoftwareSerial.h>

#define DEBUG true

SoftwareSerial esp8266(2,3); // make RX Arduino line is pin 2, make TX Arduino line is pin 3.
                             // This means that you need to connect the TX line from the esp to the Arduino's pin 2
                             // and the RX line from the esp to the Arduino's pin 3
void setup()
{
  Serial.begin(9600);
  esp8266.begin(9600); // your esp's baud rate might be different
   Serial.print("START");
  pinMode(11,OUTPUT);
  digitalWrite(11,LOW);

  pinMode(12,OUTPUT);
  digitalWrite(12,LOW);

  pinMode(13,OUTPUT);
  digitalWrite(13,LOW);

  sendData("AT+RST\r\n",2000,DEBUG); // reset module
  sendData("AT+CWMODE=2\r\n",1000,DEBUG); // configure as access point
  sendData("AT+CIFSR\r\n",1000,DEBUG); // get ip address
  sendData("AT+CIPMUX=1\r\n",1000,DEBUG); // configure for multiple connections
  sendData("AT+CIPSERVER=1,80\r\n",1000,DEBUG); // turn on server on port 80
}

void loop()
{
  if(esp8266.available()) // check if the esp is sending a message 
  {


    if(esp8266.find("+IPD,"))
    {
     delay(1000); // wait for the serial buffer to fill up (read all the serial data)
     // get the connection id so that we can then disconnect
     int connectionId = esp8266.read()-48; // subtract 48 because the read() function returns 
                                           // the ASCII decimal value and 0 (the first decimal number) starts at 48

     esp8266.find("pin="); // advance cursor to "pin="

     int pinNumber = (esp8266.read()-48)*10; // get first number i.e. if the pin 13 then the 1st number is 1, then multiply to get 10
     pinNumber += (esp8266.read()-48); // get second number, i.e. if the pin number is 13 then the 2nd number is 3, then add to the first number

     digitalWrite(pinNumber, !digitalRead(pinNumber)); // toggle pin    

     // make close command
     String closeCommand = "AT+CIPCLOSE="; 
     closeCommand+=connectionId; // append connection id
     closeCommand+="\r\n";

     sendData(closeCommand,1000,DEBUG); // close connection
    }
  }
}

/*
* Name: sendData
* Description: Function used to send data to ESP8266.
* Params: command - the data/command to send; timeout - the time to wait for a response; debug - print to Serial window?(true = yes, false = no)
* Returns: The response from the esp8266 (if there is a reponse)
*/
String sendData(String command, const int timeout, boolean debug)
{
    String response = "";

    Serial.println(esp8266.print(command)); // send the read character to the esp8266

    long int time = millis();
    while( (time+timeout) > millis())
    {

      while(esp8266.available())
      {
        Serial.print("Coming");

        // The esp has data so display its output to the serial window 
        char c = esp8266.read(); // read the next character.
        response+=c;
      }  
    }



    if(debug)
    {
      Serial.print(response);
    }

    return response;
}

the problem is i am not getting any output from esp module but arduino is transmitting the data. power supply for esp is given by 3.3v regulator (LD3.3)feeding 12v from arduino power supply adapter to regulator input . TX esp to rx arduino arduino tx to esp rx by voltage divider (R1=1k and R2=1.8k) esp gnd to arduino gnd chpd and esp vin are 3.3v from regulator Can anyone tell me where the problem is ?

4
  • I see you have plenty of debug traces sent to Serial, could you copy what you get on the serial console and paste it in your question? That could help checking out your issue.
    – jfpoilpret
    Commented May 1, 2016 at 12:45
  • I don't get any data from the esp device ,If esp data available from the device i am printing the response from serial terminal.. But No data coming Commented May 2, 2016 at 11:00
  • This is not actually what I asked: there are lots of Serial.print() in your code, it would be interesting to show exactly what gets printed to the serial console right from the start of the program.
    – jfpoilpret
    Commented May 2, 2016 at 19:48
  • Also, I am surprised by the baud rate used to talk with the ESP. In newer versions, the default rate should be 115200, not 9600.
    – jfpoilpret
    Commented May 2, 2016 at 19:49

1 Answer 1

1

Try powering the ESP from an external 3.3V power supply if possible - some people say the Arduino 3.3V regulator may not provide enough power for it (it is quite power hungry at startup).
Another option worth trying is to put a 100uF capacitor between ESP VCC and GND. Put some small delay at the beginning of your setup() function if you do that just in case.
Also, there are several pins you need to pull UP: CH_PD, RESET, GPIO0. If you have GPIO15 broken out (depends on the board), pull it to ground. I have also noticed the ESP won't boot properly if GPIO2 is LOW - either leave it floating or pull it up.
Here is a picture you can use as a guide
Of course, you should make sure the ESP is flashed with the AT commands firmware (they usually are) and your baud rate is correct. If you don't know - try 9600, 57600, 115200.
If you have a USB to TTL converter, it might be better (easier) to test your setup using it, without Arduino. Any serial terminal program (including Arduino IDE Serial Monitor) will be fine. Just make sure you send both CR and LF for new lines. If you send "AT" and receive "OK" your wiring is correct, if you don't - it is not.

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.