UART2 in esp32 won't work after booting up.

I have been trying to establish communication between DOIT ESP32-devkit V1 and arduino uno using the uart. I have used the software serial in the arduino uno and hardware serial in the esp32.

The issue is that the uart communication in ESP32 only works when i unplug and replug the jumper wire that I have connected to the hardware uart serial pin (RX 16, TX 17). The communication seems to work satisfactorily when i unplug and replug after bootup. But, it doesn’t start automatically when it boots up.

The sender ESP32 Code:

#define RXD2 16
#define TXD2 17
void setup() {
  // Note the format for setting a serial port is as follows: Serial2.begin(baud-rate, protocol, RX pin, TX pin);
  //Serial1.begin(9600, SERIAL_8N1, RXD2, TXD2); //Tried with serial1 same problem
  Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
  Serial.println("Serial Txd is on pin: "+String(TX));
  Serial.println("Serial Rxd is on pin: "+String(RX));
  Serial.println("i am in setup");
void loop() { //Choose Serial1 or Serial2 as required
  Serial.println("i am in loop");
  while (Serial2.available()) {
    Serial.println("mYSerial available");
    String str = "<Hello world, 12, 21.34>";
    String f[10] ;
    f[0] = "<1.111a>";
    f[1] = "<2.222b>";
    f[2] = "<3.333c>";
    f[3] = "<4.444d>";
    f[4] = "<5.555e>";
    f[5] = "<6.666f>";
    f[6] = "<7.777g>";
    f[7] = "<8.888h>";
    f[8] = "<9.999i>";
    for(int i =0;i <9;i++) {

The Receiver Arduino uno code:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // RX, TX

const byte numChars = 32;
char receivedChars[numChars];
char tempChars[numChars];        // temporary array for use when parsing

      // variables to hold the parsed data
char messageFromPC[numChars] = {0};
int integerFromPC = 0;
float floatFromPC = 0.0;

boolean newData = false;


void setup() {
    Serial.println("This demo expects 3 pieces of data - text, an integer and a floating point value");
    Serial.println("Enter data in this style <HelloWorld, 12, 24.7>  ");


void loop() {
    if (newData == true) {
        strcpy(tempChars, receivedChars);
            // this temporary copy is necessary to protect the original data
            //   because strtok() used in parseData() replaces the commas with \0
        newData = false;


void recvWithStartEndMarkers() {
    static boolean recvInProgress = false;
    static byte ndx = 0;
    char startMarker = '<';
    char endMarker = '>';
    char rc;

    while (mySerial.available() > 0 && newData == false) {
        rc =;

        if (recvInProgress == true) {
            if (rc != endMarker) {
                receivedChars[ndx] = rc;
                if (ndx >= numChars) {
                    ndx = numChars - 1;
            else {
                receivedChars[ndx] = '\0'; // terminate the string
                recvInProgress = false;
                ndx = 0;
                newData = true;

        else if (rc == startMarker) {
            recvInProgress = true;


void parseData() {      // split the data into its parts

    char * strtokIndx; // this is used by strtok() as an index

    strtokIndx = strtok(tempChars,",");      // get the first part - the string
    strcpy(messageFromPC, strtokIndx); // copy it to messageFromPC
    strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
    integerFromPC = atoi(strtokIndx);     // convert this part to an integer

    strtokIndx = strtok(NULL, ",");
    floatFromPC = atof(strtokIndx);     // convert this part to a float



void showParsedData() {
    Serial.print("Message ");
    Serial.print("Integer ");
    Serial.print("Float ");

The receiver code works fine. But in the sender (esp32) it wont get into serial2 loop unless I unplug the jumper and plug it back. I am unable to figure the issue. I also use a level shifter so both devices are working at safe voltage levels.

Thank you for the help in advance.

SoftwareSerial on a UNO at 115200 baud, I am surprised it ever worked at that speed, slow it down a lot ?

This looks odd;

  Serial1.begin(9600, SERIAL_8N1, RXD2, TXD2);
  Serial2.begin(115200, SERIAL_8N1, RXD2, TXD2);

Two serial ports on the same pins ?

Thanks for the reply @srnet. That line you mentioned is commetted out. It only uses the default serial and serial2. I did try to lower the baud rate, but same problems persists. I think the receiver side is fine. It works flawless (even at 115200 & 9600 baud rate). But, I still have to unplug and replug the uart wires to get the esp32 to start sending data.

That line you mentioned is commetted out.

It is now, after the edit.