/*
* Use three serial ports on an ESP32, with slow baud for one link
* https://wokwi.com/projects/470219312162010113
// somewhat per https://circuits4you.com/2018/12/31/esp32-hardware-serial2-example/
* There are three serial ports on the ESP known as U0UXD, U1UXD and U2UXD.
*
* U0UXD is used to communicate with the ESP32 for programming and during reset/boot.
* U1UXD is unused and can be used for your projects. Some boards use this port for SPI Flash access though
* U2UXD is unused and can be used for your projects.
*
*/
const byte RXD1=26;
const byte TXD1=27;
const byte RXD2=16;
const byte TXD2=17;
int baudrate = 4; // bits-per-second
void setup() {
// Note the format for setting a serial port is as follows: Serial2.begin(baud-rate, protocol, RX pin, TX pin);
Serial0.begin(9600);
Serial1.begin(baudrate, SERIAL_8N1, RXD1, TXD1);
Serial2.begin(baudrate, SERIAL_8N1, RXD2, TXD2);
Serial.println("Serial Txd is on pin: "+String(TX));
Serial.println("Serial Rxd is on pin: "+String(RX));
Serial.println("Serial TX1 is default on pin: "+String(TX1));
Serial.println("Serial RX1 is default on pin: "+String(RX1));
Serial.println("Serial TX2 is default on pin: "+String(TX2));
Serial.println("Serial RX2 is default on pin: "+String(RX2));
Serial.println("Serial0 Txd is on pin: "+String(TX));
Serial.println("Serial0 Rxd is on pin: "+String(RX));
Serial.println("Serial1 Txd is on pin: "+String(TXD1));
Serial.println("Serial1 Rxd is on pin: "+String(RXD1));
Serial.println("Serial2 Txd is on pin: "+String(TXD2));
Serial.println("Serial2 Rxd is on pin: "+String(RXD2));
Serial0.println("Hello from Serial0"); // Serial0 is an alias for Serial
Serial.println("This echoes terminal input (Serial0) out Serial1(27), \n reads it in on Serial2 (16) and then echoes it out on the terminal");
}
void loop() { //Choose Serial1 or Serial2 as required
if(Serial0.available()){
char x = Serial0.read();
Serial1.print(x);
}
if(Serial1.available()){
char x = Serial1.read();
Serial2.print(x);
}
if (Serial2.available()) {
char x = Serial2.read();
Serial.print(x);
}
}Serial0 (terminal)
Serial1
RX1
TX1
Serial2
TX
RX
Pass characters through three serial ports,
but with a very slow baud rate in an intermediate link.