-->
Page 1 of 1

esp01 software serial

PostPosted: Sun Mar 13, 2016 12:55 pm
by pollux
Hi everyone,

I'm trying to get serial data from an external device with my ESP8266 and forward it to an arduino.
I am using an ESP8266 version 01 with arduino IDE.

Programming and communicatiing with the arduino through TX and RX is OK.
However, I could not manage to use GPIO2 using softwareserial (https://github.com/plerup/espsoftwareserial)

Did anyone here has ever used softwareserial with an ESP8266 v01 ? which pin do you address in your code ?

Code: Select allSoftwareSerial esp8266(3,4);  // I tried 2,3 before.
#define startFrame 0x02
#define endFrame 0x03

void setup() {
  // put your setup code here, to run once:
  Serial.begin(1200);
  esp8266.begin(1200);
 
Serial.println("Setup complete");
}

void loop()
{
  Serial.println("START READING");
  // Variable to stock received chars
  char charIn = 0;

  // loop waiting start frame
  while (charIn != startFrame)
  {
    charIn = esp8266.read() & 0x7F;
    Serial.print("read char : ");
    Serial.println(charIn);
  }
 
  // Loop to write the interesting frame
  while (charIn != endFrame)
  {
    // if char available, follow
    if (esp8266.available() >0 )
    {
      // forgetting 8th bit
      charIn = esp8266.read()& 0x7F;
      Serial.print(charIn);
    }
  }
 
  // CR at the end of the frame
  Serial.println("");
}