I'm having trouble receiving data on Serial2. I connected Tx2(pin 16) to Rx2(pin 17) and put together a simple test sketch:
void setup() {
// Initialize Serial2 with a baud rate of 9600
Serial2.begin(9600);
// Initialize Serial with a baud rate of 9600
Serial.begin(9600);
}
void loop() {
// Send a test message out Serial2
Serial2.println("Hello from Serial2!"); //Send message out Tx2(pin 16)
// Read data from Serial2 (RX2) pin 17
while (Serial2.available()) {
char receivedChar = Serial2.read(); //Read message in Rx2(pin 17)
// For testing purposes, I;ll just print it to the Serial Monitor
Serial.println(receivedChar);
}
// Add a delay to avoid flooding the Serial Monitor
delay(1000);
}
I must be missing something, but this isn't working. Does anyone see anything that I missed?