ESP8266 non reliable responds to Arduino Code

First of all, first time making a Thread here. I love to work with the Arduino and this community here!

I am running an Arduino Uno and first time trying to connect it to the world wide web.

I have been reading a lot about this ESP8266 and I want to say at this point i am using the WIFI Module as an "Addon" with my Arduino and not running it standalone as a chip!

I am using my 3V3 output from the Arduino to power up the ESP8266 module and also use the 3V3 for the CH_PD to enable the chip.
To make sure that this setup works completely fine, I am communicating with the chip first without any Arduino code. As I dont have any Serial to USB converter, I am just using my Arduino as a Bridge to communicate with the chip. I am setting the RESET Pin of the Arduino to GND and TX to TX and RX to RX from Arduino to ESP8266. Now i can easily send commands to the ESP8266 with the serial monitor:

Everything works perfect with that setup. I assume that the ESP8266 is working absolutely fine!

Sending the commands:
AT
AT+GMR
AT+CWMODE=?

BUT as soon as I try to communicate with the ESP8266 through my code it's just not giving me the responds i want.... Well actually half and half (look the picture to see what I mean):

Sending the same commands:
AT
AT+GMR
AT+CWMODE=?

It's not about the serial connection from Arduino to the computer because I can use the

Serial.println("Random stuff")

without any problem....

You can imagine that this is a big problem as I need the responds from my ESP8266 to do anything....

Here is my code for communicating with my ESP8266 (very shortened):

#include <Arduino.h>
#include <SoftwareSerial.h>

#define RX 3
#define TX 2
SoftwareSerial esp8266(RX,TX);

void sendCommand(String, char[], size_t, int);                      //Explanation where the function is
void cleanArray(char[], size_t);                                             //Explanation where the function is


//Buffer for saving the response of the ESP8266
char response[512];

void setup() {

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


    //Making sure the buffer is empty
    cleanArray(response, sizeof(response)/sizeof(response[0]));
    

    //-----------------------------------------------------------------------------------------
    //AT command to ESP8266
    sendCommand("AT", response, sizeof(response)/sizeof(response[0]),100);
    Serial.println(response);

    cleanArray(response, sizeof(response)/sizeof(response[0]));
    Serial.println();
    

    //-----------------------------------------------------------------------------------------
    //GMR command to ESP8266
    sendCommand("AT+GMR", response, sizeof(response)/sizeof(response[0]),3000);
    Serial.println(response);
    
    cleanArray(response, sizeof(response)/sizeof(response[0]));
    Serial.println();
    

    //-----------------------------------------------------------------------------------------
    //SETTING MODE command to ESP8266
    sendCommand("AT+CWMODE=?", response, sizeof(response)/sizeof(response[0]),500);
    Serial.println(response);

    cleanArray(response, sizeof(response)/sizeof(response[0]));          
    Serial.println();

}

void loop() {
    //do nothing
    delay(500);
}




/*
Function for sending commands to the ESP8266;
   String command:    command to send to the ESP8266
   char* resp:             saving the respond of ESP8266
   size_t size:             size of the buffer
   int delayTime:        how much delay after command.... waiting for the chip to be done
*/

void sendCommand(String command, char* resp, size_t size, int delayTime){
  String response = "";
  esp8266.println(command);
  delay(delayTime);
  while(esp8266.available() > 0){
    delay(3);
    char inbyte = esp8266.read();
    response += inbyte;
  }
  
  response.toCharArray(resp, size);
}




//Function to clean the buffer

void cleanArray(char clean[], size_t size){
  for(int i = 0; i < size; i++){
    clean[i] = "";
  }
}

I really hope there is somebody have a opinion about that.... I am arguing with that ESP8266 for 2 full days to make it a reliable respond...

A weird thing to add here:

I am normally using sloeber (Eclipse) for writing and flashing my code but the serial monitor there is giving me completely non sense when sending the respond from the ESP8266 to the computer. It seems like only the Arduino IDE can decrypt a little of the bits.
Also tried Atom, same result as Eclipse

Would be so thankful for any answer!

EDIT 1:

I think i found the reason for that werid response of the ESP8266. I tried to use the <AltSoftSerial.h> to open the serial connection to the ESP8266 and i can tell a difference to <SoftwareSerial.h>. But i still don't know how to get a proper serial connection for transreceive data between arduino and ESP8266. Does anyone have an idea?

possible causes of possible ESP-01 bad behavior

  1. inadequate 3.3V power supply usually by trying to use the Arduino Uno's 3.3V output; it is a crapshoot
  2. improper/inadequate pull-up resistors on some of the pins
  3. improper voltage level's on the RX pin

https://tttapa.github.io/ESP8266/Chap01%20-%20ESP8266.html

a) don't use 3.3V from Arduino for the ESP8266.
b) don't use the setup you have choosen - program the ESP8266 and let the Uno act as slave to the ESP.

Thanks for a reply on my problem!

I was thinking about the power supply from the Arduino too. I connected to ESP8266 directly to my PC (with my Arduino as a Bridge, RESET pin to GND; make it a USB-Serial-Converter) and still using my Arduino as Power supply. Just like i described in my first post....

I wrote a code which is sending the three commands out of my first post in a loop and then printing the respond to my computer. After one hour i was looking through the responses and everything seemed perfect with that....
I assuming just for these 3 commands the power supply should be enough. As soon as i use SoftwareSerial or AltSoftSerial its causing me these weird responses.

Don't get me wrong, i will use an external power supply. But right now i am unable to get one. So i just want to test the connection between the Arduino and ESP8266.

@noiasca
By saying your option b) you mean that I should programm the ESP8266 directly and then just sending information to the Arduino and let it do the work? As the communication between Arduino and ESP8266 is not working I assume that this will give me the same result? Because I will have to connect the ESP8266 to my SoftwareSerial pins again --> maybe same problem ?

@ieee4888
option 2.: What can i do about it? Adding a pull-up resistor to my circuit? Which pins do you mean?
If that is a problem, why is it not a problem when using the Arduino as a Bridge (USB-Serial-Converter)

option3.: Should i just test it with a voltmeter to make sure its working? Try other pins for the serial connection?

Is there any other option for making the serial connection between the two devices? Like using the TX/RX from the Arduino for communicating to ESP8266 and computer at the same time?

The ESP-01 default firmware is the AT firmware usually at 115200.

If you want to debug, you need to use software serial library and a USB-TTL adapter to communicate with the ESP-01 on pins other than 0 and 1. It is much easier this way.

I would advise against using an Arduino as the "bridge".
Buy a USB-TTL adapter with the CP2102 IC.
This IC runs at 3.3V so you don't need to do any level shifting when communicating with the ESP-01 module.

I highlly recommend reading WiFi Module ESP8266 – 1. Getting started with AT commands | alselectro

.

Thanks for that answer.

I am not sure if you understood what I am trying to do...

I was just using my Arduino as a bridge to make sure the ESP8266 works. That is not how I want to include it later in my project. I want to access the ESP8266 through my code. The bridge with the Arduino was just the testing. And with the testing i am sure, that the ESP8266 works and that the power supply of the Arduino is enough for the commands:

AT
AT+GMR
AT+CWMODE=?

Like I have written I was using the SoftwareSerial library but I am getting these werid responses from the ESP8266 when using my Arduino on Pins 10 and 11, also tried 2 and 3. It's just half cryptic and half readable (look at my first post to see the responses)

I was reading your link, it's about the USB-Serial Converter. Like I said i am not able to get one right now. And when I use my Arduino as the USB-Serial Converter everything is fine.

Basically what I want to do is sending a message from my phone through the network to the ESP8266 and then send that message through the serial port to the Arduino to make something work.... But the serial connection between Arduino and ESP8266 doesnt work

Read the link I posted.

@ieee488

I hope you can help me out a little bit more. I have read through both of your links again.
I understand what they do. They use the chip as a standalone microcomputer.
In the first link you posted (A Beginner's Guide to the ESP8266) they talk about the boards with more GPIO pins than i have. I only have two, GPIO0 and GPIO2. That is not enough pins for what i need. That is why i want to use my Arduino Uno to make things work.

I get a little confused here. Is there another option to use more GPIO pins of my ESP8266? I have 8 pins all together

In the second link there is the following(WiFi Module ESP8266 – 1. Getting started with AT commands | alselectro):

You can simply connect any microcontroller to ESP module and start pushing data up to internet.

That is exactly what I want to do. But he doesnt write how to do that.

The simples thing for you to do is to abandon what you have and use https://www.cnx-software.com/2016/03/22/getting-started-with-wemos-d1-mini-esp8266-board-dht-relay-shields/

I dont need to abandon my stuff :o :o :o

I finally found the solution!
For other people trying to find a solution:

This is what I was looking for. I am sending a message from my phone to the ESP8266 over the network and then transmit it via serial to the arduino and do stuff there. So I had a clue the whole time :smiley: :smiley:

I am using the TX/RX of the Arduino to connect it to the ESP8266 and for debugging I using my LCD.

Bl4DEx:
I dont need to abandon my stuff :o :o :o

I finally found the solution!
For other people trying to find a solution:

Add WiFi to Arduino UNO - Hackster.io

This is what I was looking for. I am sending a message from my phone to the ESP8266 over the network and then transmit it via serial to the arduino and do stuff there. So I had a clue the whole time :smiley: :smiley:

I am using the TX/RX of the Arduino to connect it to the ESP8266 and for debugging I using my LCD.

Good for you!
Now work on that project and don't come back with any more questions since you "had a clue"; otherwise, we have confirmation yet again, you have no clue!

It also should be noted that the project link is useful only when you are within range of the ESP-01.
If you plan on having access when you are away from home where the ESP-01 is located, this won't work.
The linked project could have easily been completed using Bluetooth or nRF24L01 or 433 MHz modules.

.

ieee488:
...
Now work on that project and don't come back with any more questions since you "had a clue"; otherwise, we have confirmation yet again, you have no clue!

.

I think it is good that he managed to find his solution. Not only that, but he came back and supplied the solution. I personally think he should be praised for his effort and perseverance.

Well done Bl4DEx !!

ArduinoBasics:
I think it is good that he managed to find his solution. Not only that, but he came back and supplied the solution. I personally think he should be praised for his effort and perseverance.

Well done Bl4DEx !!

If he is willing to have the solution only work when he is at home, then it will work perfectly fine!

Oh, and good luck using SoftwareSerial at 115200 .

.

@ArduinoBasics
Thank you so much. I thought I am wrong here... Look for help and posting my solution to it

@ieee488
First thing, i dont know what is wrong with you but yeah... no statement on that.
Secondly, I was using SoftwareSerial the whole time but that didn't work out and I was asking why this was not working. Your sentence:

Oh, and good luck using SoftwareSerial at 115200 .

That is the answer why it was not working. You could just have posted that in a friendly answer ::slight_smile:

And for the end: Who says that my project is finished yet?

It also should be noted that the project link is useful only when you are within range of the ESP-01.

Well that is not true. I can connect it to my home AP and set it as a web server. That is the next step. But I start small and going step by step to understand what I do.

So stop giving this unnecessary responses. Thank you!

Bl4DEx:
So stop giving this unnecessary responses. Thank you!

Whatever!

I will not give you anymore "unnecessary" responses.

I will post a link to this thread the next time you come with a question about this topic.
You have all the answers why bother helping you!

.