Utilizing ESP8266 wifi module with Arduino Uno

Discussion in 'Embedded Systems and Microcontrollers' started by Tainara, Mar 19, 2016.

  1. Tainara

    Thread Starter New Member

    Sep 10, 2014

    I am trying to use an ESP8266 module to implement a wireless communication with Arduino Uno and a computer. Though I am having initial problems to make the ESP8266 works fine.

    At first I only tried a simple program to test the module with AT commands.
    The code is:
    Code (Text):
    1. #include <SoftwareSerial.h>
    2. SoftwareSerial ESP8266(2, 3); // RX, TX
    3. void setup()
    4. {
    5. Serial.begin(9600);
    6. Serial.println("Begin"); //print on screen
    7. ESP8266.begin(9600);
    8. }
    9. void loop()
    10. {
    11. //Communication (writing and reading data) with ESP8266 through Arduino IDE Serial Monitor
    12. if (ESP8266.available())
    13. Serial.write(ESP8266.read());
    14. if (Serial.available()){
    15. ESP8266.write(Serial.read());
    16. }
    17. }
    But I only got the "Begin" returned when opening the Arduino IDE serial monitor and sometimes " trash" (random non-sense and non-stop characters). By sending the AT commands I don't receive nothing back despite the indication of communication LEDs from both Arduino and ESP8266 show its on.
    I tried to set other baud rates on the above program but nothing worked.

    I read something about the ESP8266 padron baud rate normally being 115200 (tried that but also no results) and this high baud rate for communicating in Arduino UNO could not work that well so I got an example program to change the baud rate as by AT commands it's not working.
    The code:
    Code (Text):
    1. // adapted by FILIPEFLOP
    2. #include <SoftwareSerial.h>
    3. //RX pin 2, TX pin 3
    4. SoftwareSerial esp8266(2, 3);
    5. #define DEBUG true
    6. void setup()
    7. {
    8.   Serial.begin(9600);
    9.   // Configure the initial speed of ESP8266
    10.   esp8266.begin(115200);
    11.   sendData("AT+RST\r\n", 2000, DEBUG); //Reset the module
    12.   delay(1000);
    13.   Serial.println("Firmware version"); //print on serial monitor
    14.   delay(3000);
    15.   sendData("AT+GMR\r\n", 2000, DEBUG); // requires the //firmware version
    16.   // Configure the wanted speed for ESP8266 communication
    17.   sendData("AT+CIOBAUD=19200\r\n", 2000, DEBUG); // (also //tried other than 19200 but no results)
    18.   Serial.println("** End**"); //print on screen
    19. }
    20. void loop() {}
    21. String sendData(String command, const int timeout, boolean debug)
    22. {
    23.   // Send AT commands to ESP8266
    24.   String response = "";
    25.   esp8266.print(command);
    26.   long int time = millis();
    27.   while ( (time + timeout) > millis())
    28.   {
    29.     while (esp8266.available())
    30.     {
    31.       // The esp has data so display its output to the serial window
    32.       char c = esp8266.read(); // read the next character.
    33.       response += c;
    34.     }
    35.   }
    36.   if (debug)
    37.   {
    38.     Serial.print(response);
    39.   }
    40.   return response;
    41. }
    This also shows me on Serial Monitor only what I print "Firmware version" and "***End***", nothing more, and actually it should shows something like this:
    (photo from FILIPEFLOP, the site from where I got the code and this is what showed in their experience)

    Some adds:
    ESP8226 pin scheme

    Physical connection scheme:
    Also read about the ESP8266 possibly consuming more current than Arduino Uno can stand so also tried this not connecting the Vcc of ESP8226 to 3V3 Arduino pin but to the supply of an external stable source (and yes, connected the GND of the source with the Arduino, the ESP8226 and the divider GNDs) but again it didn't work.

    *Attached the ESP8266 datasheet

    Someone could help with that please?
    boltspinner and 13thJenius like this.
  2. shteii01

    AAC Fanatic!

    Feb 19, 2010
  3. tracecom

    AAC Fanatic!

    Apr 16, 2010
    Very few members here will read that much in a single post.

    There is a procedure for programming the ESP8266 with the Arduino IDE that works. It is detailed here. There are other articles by the same author dealing with the ESP8266; perhaps one of them will help.
    boltspinner likes this.
  4. GetDeviceInfo

    AAC Fanatic!

    Jun 7, 2009
    I will drive an esp8266 with an RS232 convertor driven off a com port. This way you can write AT commands and receive responses on a terminal program. Once your confident things are working, program your arduino accordingly.
  5. GopherT

    AAC Fanatic!

    Nov 23, 2012
    The IDE is not perfect for the 8266 and development seems to have stopped about a year ago - although plenty of people are begging for it.

    There is a also a method with Lua.

    Note, that you need to reflash your chip if you tried the Lua or Arduino and want to go back to AT commands. Also, some suppliers don't have the default AT commands when the chip is shipped.

    OP should read the link you posted.
  6. Tainara

    Thread Starter New Member

    Sep 10, 2014
    I already read a lot about the issue before starting the practical part, just got the same problem as many people I found when putting this theory in action. Anyway a friend shared me a program and everything else worked fine after I tried it.
  7. cleberaosantana

    New Member

    Aug 17, 2017
    Hi Tainara, I have those problems too, which program did you use to fix it?