I have the following code example:
#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);
Serial.begin(115200);
//Serial1.begin(9600, SERIAL_8N1, RXD2, TXD2);
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));
}
void loop() { //Choose Serial1 or Serial2 as required
while (Serial2.available()) {
Serial.print(char(Serial2.read()));
}
}
Which successfully compiles for an adafruit feather esp32s3 but does NOT compile for the esp32s2. I get the following error for the esp32s2:
error: 'Serial2' was not declared in this scope
I can make it compile in a few ways but the only way I can get it to work is:
- Finding and replacing all instances of Serial2 with Serial1
I figured that out by trial and error, and I am not sure I understand the issue I ran into and whether this is the best fix for it. Does anyone here have any insight?