Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By upesh.jindal
#56642 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()));
  }
}

User avatar
By upesh.jindal
#56687 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!!