Skip to main content
Notice removed Canonical answer required by CommunityBot
Bounty Ended with no winning answer by CommunityBot
Male question more compact
Source Link
Mercury
  • 101
  • 1
  • 5

example: I'm using a predefined function to send the data, and sending a simple AT command (again, using RXTX conncted to Arduino RXTX everything works well and I get OK).

bool sendCommand(const String& cmd,uint64_t timeout,bool vrbs = false,String* responseP = 0)
{
    String strCntnr;
    String& response = responseP? *responseP: strCntnr;
    response = "";
    if(vrbs)
        Serial.print("RX: "+cmd+ "...");

    esp8266.print(cmd+"\r\n"); // send the read character to the esp8266

    for(uint64_t time = millis();(time+timeout) > millis();)
    for(;esp8266.available();response+=(char)esp8266.read());

    bool ok = response.length()>0;

    response.replace("\r\n"," ");
    if(vrbs)
        Serial.println(ok? "OK ("+response+")":"ERROR");   
    return ok;
}

Setup function:

SoftwareSerial esp8266(3, 2); // RX, TX
void setup() {
    esp8266.begin(115200 );
    Serial.begin(115200 );
   
    sendCommand("AT",2000,true);
...
}

And output:

AT...OK (AR CטjµLר)

or:

AT...OK (AjCH´Dטk×Hר)

or:

RX: AT...OK (AR CטjµD�)

,or any other random string...

EDIT:

I've uptade the code I'm running to a simple one:

#include <SoftwareSerial.h>
SoftwareSerial esp8266(11, 10); // RX, TX
void setup() {
    // put your setup code here, to run once:
    esp8266.begin(19200);
    Serial.begin(115200 );
}

void loop() {
    esp8266.write("AT\r\n");
    String buffer;
    Serial.print("SENDING AT...");
    for(uint64_t time = millis();(time+1000) > millis();)
       for(;esp8266.available();buffer+=(char)esp8266.read());
    buffer.replace("\r\n"," ");
    Serial.println("RESPONSE:" + buffer);
}

I've tried changing the SerialMonitor baud rate, the input pins, but results are all the same.

I've recently changed the MCU(uno) to a different and theeven a different esp module from a different supplier, but results are all I am still getting the same results! I can't be the first one to encounter such phenomena...

example: I'm using a predefined function to send the data, and sending a simple AT command (again, using RXTX conncted to Arduino RXTX everything works well and I get OK).

bool sendCommand(const String& cmd,uint64_t timeout,bool vrbs = false,String* responseP = 0)
{
    String strCntnr;
    String& response = responseP? *responseP: strCntnr;
    response = "";
    if(vrbs)
        Serial.print("RX: "+cmd+ "...");

    esp8266.print(cmd+"\r\n"); // send the read character to the esp8266

    for(uint64_t time = millis();(time+timeout) > millis();)
    for(;esp8266.available();response+=(char)esp8266.read());

    bool ok = response.length()>0;

    response.replace("\r\n"," ");
    if(vrbs)
        Serial.println(ok? "OK ("+response+")":"ERROR");   
    return ok;
}

Setup function:

SoftwareSerial esp8266(3, 2); // RX, TX
void setup() {
    esp8266.begin(115200 );
    Serial.begin(115200 );
   
    sendCommand("AT",2000,true);
...
}

And output:

AT...OK (AR CטjµLר)

or:

AT...OK (AjCH´Dטk×Hר)

or:

RX: AT...OK (AR CטjµD�)

,or any other random string...

EDIT:

I've uptade the code I'm running to a simple one:

#include <SoftwareSerial.h>
SoftwareSerial esp8266(11, 10); // RX, TX
void setup() {
    // put your setup code here, to run once:
    esp8266.begin(19200);
    Serial.begin(115200 );
}

void loop() {
    esp8266.write("AT\r\n");
    String buffer;
    Serial.print("SENDING AT...");
    for(uint64_t time = millis();(time+1000) > millis();)
       for(;esp8266.available();buffer+=(char)esp8266.read());
    buffer.replace("\r\n"," ");
    Serial.println("RESPONSE:" + buffer);
}

I've tried changing the SerialMonitor baud rate, the input pins, the MCU and the esp module, but results are all the same.

example:

#include <SoftwareSerial.h>
SoftwareSerial esp8266(11, 10); // RX, TX
void setup() {
    // put your setup code here, to run once:
    esp8266.begin(19200);
    Serial.begin(115200 );
}

void loop() {
    esp8266.write("AT\r\n");
    String buffer;
    Serial.print("SENDING AT...");
    for(uint64_t time = millis();(time+1000) > millis();)
       for(;esp8266.available();buffer+=(char)esp8266.read());
    buffer.replace("\r\n"," ");
    Serial.println("RESPONSE:" + buffer);
}

I've tried changing the SerialMonitor baud rate, the input pins, but results are all the same.

I've recently changed the MCU(uno) to a different and even a different esp module from a different supplier, I am still getting the same results! I can't be the first one to encounter such phenomena...

added 3 characters in body
Source Link
Mercury
  • 101
  • 1
  • 5
#include <SoftwareSerial.h>
SoftwareSerial esp8266(11, 10); // RX, TX
void setup() {
    // put your setup code here, to run once:
    esp8266.begin(19200);
    Serial.begin(115200 );
}

void loop() {
    esp8266.write("AT\r\n");
    String buffer;
    Serial.print("SENDING AT...");
    for(uint64_t time = millis();(time+1000) > millis();)
       for(;esp8266.available();buffer+=(char)esp8266.read());
    buffer.replace("\r\n"," ");
    Serial.println("RESPONSE:" + buffer);
}
#include <SoftwareSerial.h>
SoftwareSerial esp8266(11, 10); // RX, TX
void setup() {
    // put your setup code here, to run once:
    esp8266.begin(19200);
    Serial.begin(115200 );
}

void loop() {
    esp8266.write("AT\r\n");
    String buffer;
    Serial.print("SENDING AT...");
    for(uint64_t time = millis();(time+1000) > millis();)
    for(;esp8266.available();buffer+=(char)esp8266.read());
    buffer.replace("\r\n"," ");
    Serial.println("RESPONSE:" + buffer);
}
#include <SoftwareSerial.h>
SoftwareSerial esp8266(11, 10); // RX, TX
void setup() {
    // put your setup code here, to run once:
    esp8266.begin(19200);
    Serial.begin(115200 );
}

void loop() {
    esp8266.write("AT\r\n");
    String buffer;
    Serial.print("SENDING AT...");
    for(uint64_t time = millis();(time+1000) > millis();)
       for(;esp8266.available();buffer+=(char)esp8266.read());
    buffer.replace("\r\n"," ");
    Serial.println("RESPONSE:" + buffer);
}
#include <SoftwareSerial.h>
SoftwareSerial esp8266(11, 10); // RX, TX
void setup() {
    // put your setup code here, to run once:
    esp8266.begin(19200);
    Serial.begin(115200 );
}

void loop() {
    esp8266.write("AT\r\n");
    String buffer;
    Serial.print("SENDING AT...");
    for(uint64_t time = millis();(time+1000) > millis();)
    for(;esp8266.available();buffer+=(char)esp8266.read());
    buffer.replace("\r\n"," ");
    Serial.println("RESPONSE:" + buffer);
}

And the output: here enter image description here

#include <SoftwareSerial.h>
SoftwareSerial esp8266(11, 10); // RX, TX
void setup() {
  // put your setup code here, to run once:
  esp8266.begin(19200);
  Serial.begin(115200 );
}

void loop() {
esp8266.write("AT\r\n");
String buffer;
Serial.print("SENDING AT...");
for(uint64_t time = millis();(time+1000) > millis();)
  for(;esp8266.available();buffer+=(char)esp8266.read());
  buffer.replace("\r\n"," ");
Serial.println("RESPONSE:" + buffer);
}

And the output: here

#include <SoftwareSerial.h>
SoftwareSerial esp8266(11, 10); // RX, TX
void setup() {
    // put your setup code here, to run once:
    esp8266.begin(19200);
    Serial.begin(115200 );
}

void loop() {
    esp8266.write("AT\r\n");
    String buffer;
    Serial.print("SENDING AT...");
    for(uint64_t time = millis();(time+1000) > millis();)
    for(;esp8266.available();buffer+=(char)esp8266.read());
    buffer.replace("\r\n"," ");
    Serial.println("RESPONSE:" + buffer);
}

And the output: enter image description here

Tweeted twitter.com/StackArduino/status/659806913882955776
added 28 characters in body
Source Link
Mercury
  • 101
  • 1
  • 5
Loading
added 776 characters in body
Source Link
Mercury
  • 101
  • 1
  • 5
Loading
Notice added Canonical answer required by Mercury
Bounty Started worth 50 reputation by Mercury
deleted 2 characters in body; edited title
Source Link
Mercury
  • 101
  • 1
  • 5
Loading
Source Link
Mercury
  • 101
  • 1
  • 5
Loading