Serial communication between two ESP32 dev boards

RogerG
Posts: 1
Joined: Sat Mar 10, 2018 6:16 pm

Serial communication between two ESP32 dev boards

Postby RogerG » Sun Mar 11, 2018 1:02 am

I have found examples of basic arduino to arduino serial communication but have been unable to get those working between ESP32 boards. The two are connected:

Code: Select all

esp1   esp2
gnd to gnd
tx2 to rx2
rx2 to tx2
Simple sketches:

Code: Select all

//transmit sketch
void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println("test...");
  delay(1000);
}

//receive sketch
void setup() {
  Serial.begin(9600);
}

void loop() {
  String received = "";
  while (Serial.available())
  {
    received = Serial.read();
    Serial.println(received);
  }
}
What else is required to make this work? I have also tried sharing vcc/vin between them.

Thanks

viedana
Posts: 1
Joined: Wed Mar 21, 2018 3:33 pm

Re: Serial communication between two ESP32 dev boards

Postby viedana » Wed Mar 21, 2018 3:40 pm

You are using the Serial 2 on the ESP32 (it has 3). In order to use this you have to define a global object (outside of the setup or loop functions):

Code: Select all

HardwareSerial Serial2(2);
Then, to refer to this serial port, instead of using

Code: Select all

Serial
use

Code: Select all

Serial2
For examble:

Code: Select all

Serial.available()
is replaced by

Code: Select all

Serial2.available()

Vaibhavi
Posts: 1
Joined: Mon Aug 08, 2022 11:13 am

Re: Serial communication between two ESP32 dev boards

Postby Vaibhavi » Mon Aug 08, 2022 11:27 am

Receiving Code :
#define RXp2 16
#define TXp2 17
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial2.begin (SERIAL_8N1, RXp2,TXp2);
}
void loop() {
Serial.println("Message Received: ");
Serial.println(Serial2.readString());

}

Sending Code:

void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial2.begin(SERIAL_8N1, 16,17);

}

void loop() {
Serial.println("Hello");


Tried a lot of versions of these codes, want to serially communicate between two ESP32 boards but unable to do so. The receiving code works fine with arduino but not with ESP32. What changes should I make in order to establish communication?

Who is online

Users browsing this forum: No registered users and 88 guests