At the begining, i tried send AT command through Serial Monitor and obtained the feed back.
HERE IS MY CODE
CODE start-------------------------------------------------------------------------------------------------------
void setup()
{
Serial1.begin(9600);
Serial.begin(9600);
Serial.println("SoftSerial to ESP8266 AT commands test ...");
delay(100);
}
void loop()
{
if (Serial1.available()) // if the channel for ESP8266 recieve the signal
{
Serial.write(Serial1.read());
}
if (Serial.available())
{
char command=Serial.read(); //Set a variable to temporarily store the command, work as buffer
Serial1.write(command); //Send the command to EPSP82966
}
}
CODE end------------------------------------------------------------------------------------------------------------
When I send "AT" via Serial monitor, however, it doesn't give a feedback "OK"
Then I add the follow code one above
ADDITIONAL CODE start----------------------------------------------------------------------------------------
#include <SoftwareSerial.h>
SoftwareSerial ESP8266(19,18); <-RX1 and TX1
Also i replace all Serial1 with ESP8266
ADDITIONAL CODE end----------------------------------------------------------------------------------------
It still does not work.
Then I replace ESP8266 with Serial1, here is the code
CODE START------------------------------------------------------------------------------------------
#include <SoftwareSerial.h>
SoftwareSerial ESP8266(19,18);
void setup()
{
Serial1.begin(9600);
Serial.begin(9600);
Serial.println("SoftSerial to ESP8266 AT commands test ...");
delay(100);
}
void loop()
{
if (Serial1.available())
{
Serial.write(Serial1.read());
}
if (Serial.available())
{
char command=Serial.read();
Serial1.write(command);
}
}
CODE END-------------------------------------------------------------------------------------------------------------
And it succeeds, the Serial monitor show the feedback "OK" when i send the command "AT"
I would like to know:
1. Is it a must to us SoftwareSerial? Mega2560 has 3 Serial ports, suppose it can use Serial1 2 or 3.
2. Why can't I use ESP8266 instead of Serial1(e.g ESP8266.write instead of Serial1.write) ? Even I make declear it >>>>>>>>SoftwareSerial ESP8266(19,18);, but it still can't work.
I have tried my best by still don't have any idea