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

Who is online

Users browsing this forum: Google [Bot] and 7 guests