I just bought an ESP8266 ESP05 and put in on a Arduino UNO as follows:
RX -> TX
TX -> RX
3.3V -> 3.3V
GND -> GND
I wrote a simple code to test my new ESP8266 ESP05
#define ESP8266 Serial
void setup()
{
Serial.begin(9600);
ESP8266.begin(115200);
}
void loop() {
String response = "";
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;
}
Serial.print(response);
}
But after going to Serial monitor I keep getting ERROR messages, is it normal?
Unrelated to your problem, but you really need to take the time to understand what this code does:
Serial.begin(9600);
ESP8266.begin(115200);
At the top of your sketch, you have this macro definition:
#define ESP8266 Serial
#define is a preprocessor directive. The preprocessor acts on your code before it's compiled. #define does a text replacement. So everywhere in your code where there is found "ESP8266" it will be changed to "Serial". So now let's look at that code after preprocessing:
[code] Serial.begin(9600);
Serial.begin(115200);
[/code]
You set Serial to run at 9600 baud and then immediately set it to run at 115200 baud.
Your use of this macro might make you think there is magically one serial interface for the Serial Monitor and another for the ESP8266. This is purely an illusion. The RX and TX pins on your Uno are also connected to your computer. What this means is every time you print something to the Serial Monitor, you're also printing it to the ESP8266, thus all those "ERROR" as it receives things that are not valid AT commands. You will also likely find that you can no longer upload sketches to your Uno with the ESP8266 connected to those pins.
A more sane approach is to use the SoftwareSerial library to create another serial port on some pins other than 0 and 1 on your Uno, connect the ESP8266 to those pins, and update your code accordingly. However, this has its trickiness as well. The ESP8266's AT firmware communicates at 115200 baud by default, but the SoftwareSerial library won't work reliably at that speed. So you should use the appropriate AT command (AT+UART_DEF) to set your ESP8266 to communicate at 9600 baud while you still have the connection on pins 0 and 1.
wow, actually this is my first time trying to upload something into an arduino and your comment cant make more sense. You are completely right, actually I was questioning the code, I knew something was wrong but didnt even think that the serial was shared between my computer and the module.
The only thing is that I cant use other port rather than 0 or 1 because Im using a cnc shield thats using every other pin on the board. Maybe I should just omit the error messages? anyway, there shouldn't be any error message when running without a usb connected to the board
there will be error messages, whether the USB is connected or not. What you're doing there is echoing every bit of the output from the ESP8266 right back at the ESP8266, which will output an error message, which will then be echoed right back at it, and so on forever.