Second Serial Port on ESP32 WROOM module

I am using this module :

It has TX2 / RX2 pins. How to declare this second Serial port ? I tried initializing it as Serial1. It compiled all right but resulted in non - stop reboot of the MCU.

Please let me know. Thanks !

Hey,

i found that here on a german page, you probably need a translator, but theres an example...

kind regards
finn

Hi Mogaraghu,

This is what I for Serial2 use on an ESP32 -



// Hardware Serial 2 pins
#define RXD2 16
#define TXD2 17


void setup() {
  
  // Initialize serial
  Serial.begin(9600);
  Serial2.begin(115200, SERIAL_8N1, RXD2, TXD2);    //Hardware Serial of ESP32

}

void loop() {

  // Serial 2 available
  if (Serial2.available())
  {
   
  // Do something

  }
}

HTH?

1 Like

The Espressif company has their Arduino'ish documentation

Welcome to ESP32 Arduino Core’s documentation — Arduino-ESP32 2.0.2 documentation (readthedocs-hosted.com)

Here, we go for the functionally check of the Serial Communication Ports.
1. Connect ESP32 Dev Module with UNO as per Fig-1.
uartESP32Un0Serial2
Figure-1:

2. Upload the following sketch in ESP32.

char myData[50];

void setup()
{
  Serial.begin(9600);
  Serial2.begin(9600);
}

void loop()
{
  if (Serial2.available() > 0)
  {
    byte m = Serial2.readBytesUntil('\n', myData, 50);
    myData[m] = '\0';
    Serial.println(myData);
  }
  Serial2.println("Hello! Mr. UNO.");
  delay(1000);
}

3. Upload the following sketch in UNO.

#include<SoftwareSerial.h>
SoftwareSerial SUART(2, 3);
char myData[50];

void setup()
{
  Serial.begin(9600);
  SUART.begin(9600);
}

void loop()
{
  if (SUART.available() > 0)
  {
    byte m = SUART.readBytesUntil('\n', myData, 50);
    myData[m] = '\0';
    Serial.println(myData);
  }
  SUART.println("Msg received!");
  delay(1000);
}

Output:

Msg received!
Msg received!
Hello! Mr. UNO.
Hello! Mr. UNO.
2 Likes

To all those who posted to help : THANKS :star_struck:

Declaring it as a Serial2 solved the problem.

Sorry about the late response !!

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