0

I'm trying to send data from my esp to my arduino using serial using the following codes :

esp :

server.on("/drive",HTTP_GET, handleDrive);
void handleDrive() 
{
    server.send(200,"text/html", "Drive!");
    String sendToArduino = "";
    for (int i=0;i<server.args();i++) 
    {
   sendToArduino = sendToArduino+server.argName(i)+"="+sendToArduino.arg(i)+"&";
    }
    Serial.println(sendToArduino);
}

and on arduino :

Serial.begin(9600);
esp8266.begin(115200);


if (esp8266.available()) 
{
   String  readString="";
   while (esp8266.available()) 
   {
     delay(2); 
     char c = esp8266.read();  
     readString += c;
   }
}

but when i send data from esp to arduino i get it with "noise"

Ex : "variable1=1234" i recive it on arduino "variab@e=12" What can i make to make sure that what i send is same in arduino ?

  • Two things: 1. read the serial properly (majenko.co.uk/blog/reading-serial-arduino), and 2. what baud rate are you communicating at? – Majenko Jul 7 '18 at 13:58
  • Serial.begin(9600); esp8266.begin(115200); in arduino – user863873 Jul 7 '18 at 14:02
  • Sorry, what is that delay(2)? You send one byte from the ESP in roughly 87us, and force to read it once every 2ms? – frarugi87 Jul 9 '18 at 10:01
0

Firstly you need to write a more reliable serial reading routine on the Arduino. As it stands your routine is lucky you even get what you do. You need to write a routine that doesn't care about time, but instead cares about the terminating character of the line you are receiving.

Secondly, you cannot communicate reliably using SoftwareSerial at 115200 baud. While the Arduino is capable of receiving a byte at that baud rate using bit banging, there typically isn't enough time between successive bytes to allow the Arduino to store what it has just received, and so it starts receiving partway through the next byte, corrupting both it and the following byte. That's the cause of the corruption you are seeing.

You should either slow down the baud rate (9600 is a good choice), or send the data one byte at a time and add a delay between each byte (somewhat hacky...).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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