Hello guys
I am using esp8266 to connect to wifi with arduino mega 2560. My problem is with serial communication I think. First to test the module I used bareminumum example then I try to set the esp by typing the needed commands on serial monitor and every thing works fine. My problem is when I write code to print esp8266 commands it never work. whatever I do the module not responding. I used many libraries but the result same. I don't know what is the problem exactly but it seems that the commands never reach the module by the coding and it reach the module normally when i wrote it manually to serial monitor.
last library I used is ITEADLIB_Arduino_WeeESP8266 and I tried the following code
#include "ESP8266.h"
#define SSID "ITEAD"
#define PASSWORD "12345678"
ESP8266 wifi(Serial1);
void setup(void)
{
Serial.begin(9600);
Serial.print("setup begin\r\n");
Serial.print("FW Version: ");
Serial.println(wifi.getVersion().c_str());
if (wifi.setOprToStation()) {
Serial.print("to station ok\r\n");
} else {
Serial.print("to station err\r\n");
}
if (wifi.joinAP(SSID, PASSWORD)) {
Serial.print("Join AP success\r\n");
Serial.print("IP: ");
Serial.println(wifi.getLocalIP().c_str());
} else {
Serial.print("Join AP failure\r\n");
}
Serial.print("setup end\r\n");
}
void loop(void)
{
}
The library I used will be in attachments.
the results are
setup begin
FW Version:
to station err
Join AP failure
setup end
I know the the first thing need to be checked is connection
but actually the connection should be esp_rx with arduino_tx1 d18 and esp_tx with arduino_rx1 d19 and I tried different connections. I revert rx and tx also I modify the code to use serial instead of serial1 and nothing change in the result
If anyone have an idea about what is going on here please help me
ITEADLIB_Arduino_WeeESP8266-master.zip (420 KB)
Your ESP8266 is connected to the Serial1 TX/RX pins, correct?
esp8266 is connected to software serial and serial monitor is on chip serial of arduino
SurferTim:
Your ESP8266 is connected to the Serial1 TX/RX pins, correct?
yes it is connected to serial1 port but also I tried it with other serial ports
I don't know if I state my problem clearly but anyways the model response when I use empty code for Arduino and sent at command from serial monitor but when I used code and Serial1.println("AT") for example then the module not responding at all
rajguruavi:
esp8266 is connected to software serial and serial monitor is on chip serial of arduino
I don't understand what you mean exactly but anyway I am using mega 2560 which have 4 serial ports and now I am using serial1 port to communicate with esp module. if you follow the code you will notice that I set serial1 port by this line
ESP8266 wifi(Serial1);
then the library will try to connect to the wifi by serial 1 and accordingly will show massage to screen using serial0
could you please explain what you mean exactly
I am thankful for all who tried to help me
I solved the problem by changing baud rate to 115200 instead of 9600 and this is the final change
#include "ESP8266.h"
#define SSID "home"
#define PASSWORD "qwertyuiop"
ESP8266 wifi(Serial1);
void setup(void)
{
Serial.begin(115200);
Serial1.begin(115200);
Serial.print("setup begin\r\n");
Serial.print("FW Version: ");
Serial.println(wifi.getVersion().c_str());
if (wifi.setOprToStation()) {
Serial.print("to station ok\r\n");
} else {
Serial.print("to station err\r\n");
}
if (wifi.joinAP(SSID, PASSWORD)) {
Serial.print("Join AP success\r\n");
Serial.print("IP: ");
Serial.println(wifi.getLocalIP().c_str());
} else {
Serial.print("Join AP failure\r\n");
}
Serial.print("setup end\r\n");
}
void loop(void)
{
}
Hi,
I am also using the same code and also tried your option of baudrate but did not worked out for me.
I have used below code.
#include "ESP8266.h"
#define SSID "Xender_APf402"
#define PASSWORD "vipin123"
ESP8266 wifi(Serial1);
void setup(void)
{
Serial.begin(9600);
Serial.print("setup begin\r\n");
Serial.print("FW Version: ");
Serial.println(wifi.getVersion().c_str());
if (wifi.setOprToStation()) {
Serial.print("to station ok\r\n");
} else {
Serial.print("to station err\r\n");
}
if (wifi.joinAP(SSID, PASSWORD)) {
Serial.print("Join AP success\r\n");
Serial.print("IP: ");
Serial.println(wifi.getLocalIP().c_str());
} else {
Serial.print("Join AP failure\r\n");
}
Serial.print("setup end\r\n");
}
void loop(void)
{
}
I am using atmega2560 with serial 1 only and it has level shifter in between for 5v to 3.3v bidirectional.
I am supplying power to esp8266 from outside only.
I have used SDK VERSION 0.18 and 0.22 and latest version also 2.0.1 also but it did not worked for me.
Can you let me know which SDK version you used to make it work and with which flash tool as i have already tried what was mentioned in itead but did not worked out for me.
Please help in this
It gives me below error.
setup begin
FW Version:
to station err
Join AP failure
setup end