Troubleshoot Serial2 on Arduino Mega

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?

I found my own problem. Evidently the jumper wire that I chose to use, was a little dirty. I disconnected it, cleaned the ends a bit, and it works now. Sorry to waste anyone's time.

1 Like

No problem, that is how we learn.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.