-->
Page 1 of 2

AT Commands respond manually but not through program

PostPosted: Mon Oct 17, 2016 8:01 am
by upesh.jindal
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:

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()));
  }
}


Re: AT Commands respond manually but not through program

PostPosted: Mon Oct 17, 2016 4:07 pm
by AcmeUK
Hi

This guy seems to have it working :- http://pracujlabs.io/2015/12/31/pig-surveilance.html

Interestingly he is using softwareSerial.println

Re: AT Commands respond manually but not through program

PostPosted: Tue Oct 18, 2016 7:07 am
by upesh.jindal
Thanks for responding AcmeUK!

I tried the same code with minimal ESP8266 communication from his sketch but it still doesn't work. What baffles me is that my hardware setup works through Serial Monitor when I have RX/TX on Arduino connected to ESP8266. But for code I used SoftwareSerial on pin 2 and 3 connected to RX/TX on ESP8266 and it stops working.

I'll try to communicate in my code using Serial with ESP8266 and pin 2/3 as SoftwareSerial for Serial Monitor. I have no idea if that is possible or not. I can just imagine that it should work.

Will let you know.

Again, I appreciate your response!!

Re: AT Commands respond manually but not through program

PostPosted: Tue Oct 18, 2016 7:54 am
by upesh.jindal
To respond to my previous reply: it didn't work to switch Serial and SoftwareSerial. I guess for the obvious reasons. Serial communicates only on RX/TX.

I have no idea what else to do to read the data correctly from ESP8266.