Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have connected my Arduino with an ESP8266.

When I check the ESP8266, by manually entering commands at serial monitor, I get correct results.

However, when I run this program

#include<SoftwareSerial.h>

SoftwareSerial esp8266(2,3);

void setup() {
  Serial.setTimeout(5000);
  Serial.begin(115200);
  esp8266.begin(115200);
  delay(1000);
}

void loop() {
  delay(2000);
  String command="AT";

  esp8266.println(command);
  if(esp8266.available())
  {
    while(esp8266.available())
    {
      char c=esp8266.read();
      Serial.write(c);          
    }
  }
}

I get garbage values where sometimes it has an OK in between the output:

" Received: "ÁT OK " Received: "AÔ ÏË " Received: "AÔ OK " Received: "ÁT ÏË " Received: "ÁT OË " Received: "ÁÔ OK " Received: "Á¬ OK " Received: "ÁT OË "

Could someone help me?

share|improve this question
    
Is your serial monitor configured for 115200? Did you check the ESP with a serial monitor at 115200? Can you post the garbage? Did you look on the wires with an oscilloscope? – frarugi87 Nov 25 '15 at 15:11
    
Yeah frarugi87. I kept the serial monitor at 115200. – abdul rahuman Nov 25 '15 at 16:01
    
Ok @abdul rahuman, try using if(esp8266.available()) { Serial.print("Received: \""); while(esp8266.available()) { char c=esp8266.read(); Serial.write(c); } Serial.println("\""); } and post back the output of the serial monitor – frarugi87 Nov 25 '15 at 16:26
    
@frarugi87 i got this upon your code. " Received: "ÁT OK " Received: "AÔ ÏË " Received: "AÔ OK " Received: "ÁT ÏË " Received: "ÁT OË " Received: "ÁÔ OK " Received: "Á¬ OK " Received: "ÁT OË " – abdul rahuman Nov 26 '15 at 6:37
    
@frarugi87 as you could see it prints OK sometimes at but it prints some garbage combination with OK. so please help me. – abdul rahuman Nov 26 '15 at 6:38

As noted by Matt, the baud rate for the ESP8266 can vary depending on the firmware version/manufacturer. 9600 and 115200 are the most common. If you can connect using a serial terminal program (like CoolTerm) you can then test the baudrate.

It sounds like the ESP8266 is set to 115200, but in my experience (and others') SoftwareSerial isn't capable of 115200 baud rate (despite "allowing" this as a setting). Some reports suggest as high as 57600 is workable, though in my experience 9600 is best for reliability. But you can reset this and see what the max reliable value is for you in your configuration.

How to change the baud rate on the ESP8266 will depend on the firmware version. I've had success with AT+IPR=9600. You only need to run this command once (it's a persistent setting). I'd suggest, based on your description, that this is the most likely culprit that's causing the intermittent "garbage" output you describe.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.