-->
Page 1 of 1

SoftwareSerial on longer command garbage.

PostPosted: Wed Oct 28, 2015 5:35 pm
by Dragorwyin
Hi everyone!
I have an problem with sending longer commands to ESP8266 with SerialPort Monitor. I'm using Arduino Uno and on hardware serial everything is fine, but when I trying to send for example AT+CIPSEND command by SoftwareSerial, there is garbage response and garbage command which is going to ESP8266.

Garbage AT+CIPSEND looks like:

OK
A­%AMEŐ‰5•bj


busy p...
no ip


How can I repair that without buying Arduino Mega which has more hardware serial ports?

My program:

Code: Select all#include <SoftwareSerial.h>
 
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
String dataStr = "";
int number;

void setup()
{
  Serial.begin(57600);
  esp8266.begin(57600); // your esp's baud rate might be different
}
 
void loop()
{
  if(esp8266.available()) // check if the esp is sending a message
  {
    while(esp8266.available()>0)
    {
      char c = esp8266.read(); // read the next character.
    // dataStr = dataStr + c;

     Serial.write(c);
  /*    if (c == 13) { 
        number = dataStr.indexOf('OK');
        if (number>0) {
        Serial.println("\n yolo");
        }
        dataStr = "";
      }      */
   }
 }
 
 
 
  if(Serial.available())
  {
    // the following delay is required because otherwise the arduino will read the first letter of the command but not the rest
    // In other words without the delay if you use AT+RST, for example, the Arduino will read the letter A send it, then read the rest and send it
    // but we want to send everything at the same time.
    delay(20);
   
    String command="";
   
    while(Serial.available()) // read the command character by character
    {
     
        // read one character
      command+=(char)Serial.read();
    }
    esp8266.println(command); // send the read character to the esp8266
  }
}


I hope that someone can help.

Re: SoftwareSerial on longer command garbage.

PostPosted: Tue Nov 03, 2015 5:29 am
by TijuanaKez
Hi, I'm only new to this but I found lowering the baud rate fixed garbage responses with SoftwareSerial.

Use AT+CIOBAUD or AT+IPR depending on firmware and use the same for esp8266.begin().
Start with 9600 and move up to find when it gets unstable.

Re: SoftwareSerial on longer command garbage.

PostPosted: Tue Nov 03, 2015 2:30 pm
by Dragorwyin
Oh, I didn't write... I've changed baud rate to 9600 and there is still the same problem. I just bought Arduino Mega and working on hardware serialports :)

But thanks for response, hope, that you will help someone else with your post ;)

Re: SoftwareSerial on longer command garbage.

PostPosted: Fri Nov 06, 2015 10:13 am
by Venkatesh
Don't use while loop's

Code: Select allvoid loop() {

   if (esp8266.available())
      Serial.write(mySerial.read());

   if (Serial.available())
      esp8266.write(Serial.read());

}


If you are seeing garbage always start BAUD rate from 9600.