Strange Message from esp8266

I'm trying to use an esp8266 that I bought quite a lot time ago. I configured correctly and stablish requests. But I don't know why when I'm using the pins of the arduino and using SoftwareSerial the message that I recive isn't readable.

If I switch from pins of arduino to directly control without arduino I can read correctly the message.

Anyone could guess what could be?

A guess is all we can do, because you forgot to post all of the Arduino code. Please use code tags when posting code.

Software serial does not work well or at all at Baud rates above 38400.

Ditto what @jremington said.

Probably you are using a too fast baud rate... Software Serial is unreliable at higher speeds.

Can't really say for sure because you need to post ALL your code... using code tags... this button the editor...
image

You know that instead of using the ESP8266 in this way, you can just load your sketch directly onto the ESP8266 ?

are you using software-serial-esp8266

I'm using an example that is very common.

#include <SoftwareSerial.h>  

int TxPin = 3;
int RxPin = 2;
                      
SoftwareSerial esp8266(TxPin,RxPin);                   
#define serialCommunicationSpeed 9600               
#define DEBUG true                                 

void setup()

{
  Serial.begin(serialCommunicationSpeed);  
  Serial.println("Serial Iniciado\n");
  esp8266.begin(serialCommunicationSpeed);  
  Serial.println("ESP8266 Iniciado\n");   
  InitWifiModule();                              
}

void loop()                                                         
{

  if(esp8266.available())                                           
 {    
    if(esp8266.find("+IPD,"))
    {
     delay(1000);
 
     int connectionId = esp8266.read()-48;                                                
     String webpage = "<h1>Hello World!</h1>";
     String cipSend = "AT+CIPSEND=";
     cipSend += connectionId;
     cipSend += ",";
     cipSend +=webpage.length();
     cipSend +="\r\n";
     
     sendData(cipSend,1000,DEBUG);
     sendData(webpage,1000,DEBUG);
 
     String closeCommand = "AT+CIPCLOSE="; 
     closeCommand+=connectionId; // append connection id
     closeCommand+="\r\n";    
     sendData(closeCommand,3000,DEBUG);
    }
  }
}
                                                                                                                                                                                                                                                                                                                                                              
String sendData(String command, const int timeout, boolean debug)
{
    String response = "";                                             
    esp8266.print(command);                                          
    long int time = millis();                                      
    while( (time+timeout) > millis())                                 
    {      
      while(esp8266.available())                                      
      {
        char c = (char)esp8266.read();                                     
        response+=c;  
      }  
    }    
    if(debug)                                                        
    {
      Serial.println("Comand: " + command);
      Serial.println("Response: " + response);
    }    
    return response;                                                  
}

void InitWifiModule()
{
  sendData("AT+RST\r\n", 2000, DEBUG);                                                  
  sendData("AT+CWJAP=\"******\",\"pwd\"*****", 2000, DEBUG);        
  delay (3000);
  sendData("AT+CWMODE=1\r\n", 1500, DEBUG);                                             
  delay (1500);
  sendData("AT+CIFSR\r\n", 1500, DEBUG);                                             
  delay (1500);
  sendData("AT+CIPMUX=1\r\n", 1500, DEBUG);                                             
  delay (1500);
  sendData("AT+CIPSERVER=1,80\r\n", 1500, DEBUG);                                     

}

Also the circuit that I use is these, but with diferent pins of arduino

have a look at ESP8266_01_pins
if you have a ESP-01 you need to pull up RST and CH_PD to start up the module
ESP-01S is OK it has pullups on board

I searched which esp-01 version do I have and I think is the 01S, cause the board is black (i found that here: https://aruneworld.com/embedded/esp8266/esp8266-boards/). But i don't understand what do you mean with pull up.

Any tutorial?

when loading code into flash memory or executing code from flash microcontrollers have to have certain pins in specified states HIGH or LOW, e.g. the ESP-01

the states can be achieved by the programmer hardware/software setting them or using pullup resistors connected to VCC or pulldown resistors connected to GND

here is some code to test the UNO and ESP-01 communications
ESP-01 code characters received on U0RXD are echoed back on U0TXD

//  ESP-01 blink LED and read characters from serial U0RXD  and echo back to U0TXD

void setup() {
  Serial.begin(9600);
  delay(1000);
  Serial.println();
  Serial.println("\n\nESP-01 blinking LED and read characters from serial U0RXD  and echo back to U0TXD ");
  Serial.print("LED blinking pin ");
  Serial.println(LED_BUILTIN);
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(100);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);   // turn the LED off by making the voltage LOW
  delay(100);                       // wait for a second
  // read serial U0RXD and echo it back to U0TXD
  while (Serial.available() > 0) {
    char ch = Serial.read();
    Serial.write(ch);
  }
}

and the UNO (note SoftwareSerial will not work as the code may transmit and receive at the same time)

// UNO - ESP-01 AltSoftSerial test - ESP-01 loopsback - character transmitted to it are echoed back
//  requires program ESP-01_Serial_loopback loaded in to ESP-01 and serial connections (see below)

#include <AltSoftSerial.h>

// load program ESP-01_Serial_loopback in to ESP-01
// ESP-01 U0TXD to UNO RX pin 8
// ESP-01 U0RXD to UNO TX pin 9
// ESP-01 GPIO0 and GPIO2 need to have pull-up resistors connected to ensure the module starts up correctly
// The ESP-01S has 12K resistors on the board for GPIO0, RST and CH_PD 

AltSoftSerial espSerial;

void setup() {
  Serial.begin(115200);
  Serial.println("AltSoftSerial test");
  //Begin serial communication with Arduino and SIM800L
  espSerial.begin(9600);
  Serial.println("ESP-01 serial intialized");
  Serial.println("load ESP-01_Serial_loopback in to ESP-01");
  Serial.println("ESP-01 U0TXD to UNO RX pin 8");
  Serial.println("ESP-01 U0RXD to UNO TX pin 9");
}

void loop() {
  if (Serial.available()) {
    char command = Serial.read();
    //Serial.println(command);
    espSerial.print(command);
  }
  while (espSerial.available()) {
    char reponse = espSerial.read();
    Serial.print(reponse);
  }
}

note the UNO <> ESP-01 baudrate is 9600 - at higher rate, e.g. 115200, some characters can get corrupted
UNO serial monitor output

ESP-01 blinking LED and read characters from serial U0RXD  and echo back to U0TXD 
LED blinking pin 2
UNO test 1
UNO test2 1234567890
UNO test3 abcdefghijklmnopqrstuvwxyz

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.