Reputation: 185
I have a little problem with programming with arduino uno and esp8266. I have connected the arduino uno with esp8266 module.
I get correct results when I run a empty program to test esp8266 with its command.
Manually entered commands with results:
When I give manually in serial monitor command AT it gives OK and correct results for all commands.
But when I try to automate with program I don,t get the output as it gives when I type manually at serial monitor could you please check my codes.
void setup() {
Serial.begin(115200);
}
void loop() {
delay(5000);
Serial.println("AT+RST");
while(Serial.available())
{
String s=Serial.readString();
Serial.println(s);
}
}
My next program
#include<SoftwareSerial.h>
SoftwareSerial esp8266(2,3);
void setup() {
Serial.begin(115200);
esp8266.begin(115200);
delay(1000);
}
void loop() {
delay(2000);
String command="AT+RST";
esp8266.println(command);
if(esp8266.available())
{
while(esp8266.available())
{
char c=esp8266.read();
Serial.write(c);
}
}
}
My result for this program is nothing on serial monitor.
I want to get the command in the program as string so that i could perform string operations like find or others when acting as a web server.
Someone please help me.
Upvotes: 0
Views: 488
Reputation: 1
Do one thing
#include<SoftwareSerial.h>
SoftwareSerial esp8266(2,3);
void setup() {
Serial.begin(115200);
esp8266.begin(115200);
delay(1000);
}
void loop() {
delay(2000);
String command="AT+RST\r\n";
esp8266.println(command);
c=0;
while(!esp8266.find("reset"))
{
c++;
if(c>100)
{
break;
}
}
String Response=esp8266.readString();
Serial.write(Response);
}
Try this it will work definately and if in case it didnt then please swap the rx and tx pin on arduino not in code and then it will work
Upvotes: 0
Reputation: 915
Try running the same command with both newlines and carriage returns. I've seen some ESP8266 modules in AT mode ignore commands otherwise.
// This should give you "OK" as a sanity check
Serial.print("AT\r\n");
// And then you can run this after
Serial.print("AT+RST\r\n");
Upvotes: 0