AT Commands respond manually but not through program
Posted: Mon Oct 17, 2016 8:01 am
Hi there!
I'm a newbie with Arduino and ESP8266 12-F. I am able to connect them and get response from ESP8266 through USB to Serial bridge CP2102.
All AT Commands respond properly without any special characters.
However, when I write a C program to connect with ESP8266 it responds with junk. I tried changing baud rates to lower than 115200 after reading that SoftwareSerial doesn't support higher than 57600. But the situation remains same except the fact that soft.available() returns different numbers. Following is my sketch:
I'm a newbie with Arduino and ESP8266 12-F. I am able to connect them and get response from ESP8266 through USB to Serial bridge CP2102.
All AT Commands respond properly without any special characters.
However, when I write a C program to connect with ESP8266 it responds with junk. I tried changing baud rates to lower than 115200 after reading that SoftwareSerial doesn't support higher than 57600. But the situation remains same except the fact that soft.available() returns different numbers. Following is my sketch:
Code: Select all
#include "Arduino.h"
#include "SoftwareSerial.h"
int rxPin = 4;
int txPin = 3;
SoftwareSerial soft (rxPin, txPin);
void setup ()
{
pinMode (rxPin, INPUT);
pinMode (txPin, OUTPUT);
Serial.begin (19200);
Serial.println ("Starting up...");
soft.begin (19200);
while(!Serial) {;}
while (!soft) {;}
soft.print ("AT\r\n");
while (!soft.available())
{
Serial.println ("Waiting...");
delay (200);
}
Serial.println (soft.available());
}
void loop ()
{
if (soft.available())
{
Serial.print ((char)(soft.read()));
}
}