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:
#include <SoftwareSerial.h>
SoftwareSerial ESP8266(2, 3); // RX, TX
void setup()
{
Serial.begin(9600);
Serial.println("Begin"); //print on screen
ESP8266.begin(9600);
}
void loop()
{
//Communication (writing and reading data) with ESP8266 through Arduino IDE Serial Monitor
if (ESP8266.available())
Serial.write(ESP8266.read());
if (Serial.available()){
ESP8266.write(Serial.read());
}
}
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:
// adapted by FILIPEFLOP
#include <SoftwareSerial.h>
//RX pin 2, TX pin 3
SoftwareSerial esp8266(2, 3);
#define DEBUG true
void setup()
{
Serial.begin(9600);
// Configure the initial speed of ESP8266
esp8266.begin(115200);
sendData("AT+RST\r\n", 2000, DEBUG); //Reset the module
delay(1000);
Serial.println("Firmware version"); //print on serial monitor
delay(3000);
sendData("AT+GMR\r\n", 2000, DEBUG); // requires the //firmware version
// Configure the wanted speed for ESP8266 communication
sendData("AT+CIOBAUD=19200\r\n", 2000, DEBUG); // (also //tried other than 19200 but no results)
Serial.println("** End**"); //print on screen
}
void loop() {}
String sendData(String command, const int timeout, boolean debug)
{
// Send AT commands to ESP8266
String response = "";
esp8266.print(command);
long int time = millis();
while ( (time + timeout) > millis())
{
while (esp8266.available())
{
// 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;
}
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:
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.
* I didn’t use the push buttons part.
Someone could help me with that please?