So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By Bl4DEx
#78197 First of all, first time making a Thread 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:


Image


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

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



Image



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):


Image

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


Image


It's not about the serial connection from Arduino to the computer because I can use the
Code: Select allSerial.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):

Code: Select all#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 3 full days to make it a reliable respond...

I guess it is a problem with the <SoftwareSerial.h> library.

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!