Can we change the pin no while using the program for serial communication in ESP32 board.
EX:
void loop(){
Serial2.begin(9600,SERIAL_8N1,RXD_1,TXD_1);
// after using this data
Serial2.flush();
Serial2.end();
Serial2.begin(9600,SERIAL_8N1,RXD_2,TXD_2);
//Again after using this data
Serial2.flush();
Serial2.end();
}
//but this is giving error, can anyone tell me why?
// and how to use more than 3 serial ports in ESP32
the Serial ports get defined in the Setup() not the Loop()
There are hardware ports that have predefined I/O pins. These cannot be changed.
2a) The 2nd hardware serial port has limitations, read the specification.
For 3 serial ports you will have to use a "softserial" library. This will allow you to create serial ports that are not hardware based. They also take more processor time as they are doing in software what the hardware ports do in hardware.