Esp32 Serail1 usage

For a simple project I'm in need to use 2 serial ports on my ESP32. (Now I'm testing with serial 0 and Serial1 , later on I will use serial1 and Serial2)

I've been reading in to use serial1 on this device but still cannot get it working in the test sketch

At this point using the stuff I've found on ESP32 + RS232 TTL serial communication - Programming Questions - Arduino Forum I used the code below.

When i connect a ttl - usb converter to pin 26-27 I can send data from Serial0 to Serial 1 but not from Serial1 to Serial0

Perhaps there is a better way to do this in v1.0.4. for the esp32..

Every tip / trick is welcome.

// EXAMPLE USAGE

#include <HardwareSerial.h>

//#define SerialDataBits 115200
HardwareSerial SerialTFMini( 1 );
HardwareSerial SerialController( 2 );
// serial(1) = pin27=RX green, pin26=TX white
// serial(2) = pin16=RXgreen , pin17=TX white

void setup()
{

  SerialController.begin( 9600 );
 SerialTFMini.begin(  9600, SERIAL_8N1, 27, 26 );
  
  
  Serial.begin(9600); 
  Serial1.begin(9600);  // open serial over TX and RX pins
}

void loop()
{
    Serial.println("Test print serial0");
    Serial1.println("Test print serial1");
  delay(1000);
  // read from port 0, send to port 1 ... working
  if (Serial.available())
  {
      Serial1.print(Serial.read());
  }
  // read from port 1, send to port 0 ... not working
  if (Serial1.available())
  {
    Serial.println("is er ");
      Serial.print(Serial1.read());
  }
 }

Following Secret Serial Port For Arduino/ESP32 | Hackaday I can change HardwareeSerial.cpp and get it working.

What i foud was a little different like explained and got me thinking.

#ifndef RX1
#define RX1 9
#endif

#ifndef TX1
#define TX1 10
#endif

Changing this to

#ifndef RX1
#define RX1 27
#endif

#ifndef TX1
#define TX1 26
#endif

worked :slight_smile: :slight_smile:

But . . .

If I leave the HardwareSerial.cpp like original can I not just define theRX1 and TX1 in the sketch like this and leave HardwareSerial.cpp unchanged?

#define TX1 26;
#define RX1 27;


void setup()
{
 Serial.begin(9600);
 Serial1.begin(9600);
}
void loop()
{
  //Serial.println("Test Serial 0");
  
  //Serial1.print("test serial 1");
  // read from port 1, send to port 0:
  if (Serial.available())
  // Serial1.print("test serial 1");
  
  {
      Serial1.print(Serial.read());
  }
  if (Serial1.available())
  {
   //  Serial.println("Test Serial 0");
      Serial.print(Serial1.read());
  }
  
}

Not working :frowning: :frowning:
Is this not possible or am I missing some thing?