Serial Communication Between two ESP8266

Hello falks,

I've been searching for hours for a simple (yes, simple) ESP serial communication. Haven't found anythink :frowning:

But: i must send a char from the first ESP, to the second ESP. So, only one way sending (no need to send anythink back). One has to send only, and the second has to receive only.

The char which has to be sended, don't have a certain length. So: it could be 3 letters, but also 20 letters.

Hope, I could explain you my problem.

Thanks a lot.

The most common way to do what you want,is to use Serial.print,or Serial.write to,transmit the text block.

You would either want to set up a protocol to indicate how much text is being sent, or if it’s plain text, a simple CR to terminate each message.

On the receiving end, monitor Serial.available until something arrived,mths readvcharacters until you protocol is satisfied,it uoufind a terminator (e,g, CR), then process the message, and start over again looking for another complete message.

1 Like

use the library manager to instal espsoftwareserial
sample code

// ESP8266 SoftwareSerial
// https://circuits4you.com/2016/12/14/software-serial-esp8266/

#include <SoftwareSerial.h>

// pins Rx GPIO14 (D5) and Tx GPIO 12 (D6) 
 SoftwareSerial swSer(D5, D6);//14, 12);  

void setup() {
  Serial.begin(115200);   //Initialize hardware serial with baudrate of 115200
  swSer.begin(9600);    //Initialize software serial with baudrate of 115200
  Serial.println("\nESP8266 Software serial test started");
}

void loop() {
  while (swSer.available() > 0) {  //wait for data at software serial
    Serial.write(swSer.read()); //Send data recived from software serial to hardware serial    
  }
  while (Serial.available() > 0) { //wait for data at hardware serial
    swSer.write(Serial.read());     //send data recived from hardware serial to software serial
  }
}

1 Like

Thanks man, it worked... had to change somethink according to my project, but it worked :smiley:

Sorry again, I have another problem. This code here, works. I am receiving chars, yes. But how can I combine them into one char ?

Here is the ESP code which transmitts data:

void setup() {
  Serial.begin(115200);
  
}

void loop() {
  Serial.write('H');
  Serial.write('e');
  Serial.write('l');
  Serial.write('l');
  Serial.write('o');
  Serial.write(' ');
  Serial.write('W');
  Serial.write('o');
  Serial.write('r');
  Serial.write('l');
  Serial.write('d');
  Serial.write('!');
  delay(2000);
}

And here is the Receiver code:

void setup() {
  Serial.begin(115200);
}


void loop() {
    while (Serial.available() > 0) {  //wait for data at software serial
      char receivedChar = Serial.read();
      Serial.print(receivedChar);  
    }
  delay(2000);
}

The combination of the chars, should accure in the Receiver-Code. Okay,

Meanwhile, I have googled a little, and learned, that a char is only one letter/symbol. So my question should be:

How can I combine many chars into one string ?

Meanwhile, I have fixed it myself :smiley:

Thanks anyway to all of you guys.

Here is my working code for the receiving ESP module:

String mystring;

String combined;

void setup() {
  Serial.begin(115200);
}


void loop() {
  combined="";
  
    while (Serial.available() > 0) {
      char receivedChar = Serial.read();
      String mystring(receivedChar);
      combined = combined + mystring;
    }

  
  Serial.println(combined);  
  delay(2000);
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.