Redirecting serial monitor port on Mega2560?

I am ramping up to do a project using a Maple board (leaflabs.com) with a BlueSMiRF talking to an Arduino Pro Mini with a BlueSMiRF. But to debug, I'm using an Arduino Mega instead of the Pro Mini since it has > 1 UART.

I have a communication protocol implemented already and am going to debug my connection in the following way:

  • Plug in the Bluetooth radios to UART 1 on both devices respectively (the USB connection is UART 0 on both).

  • For every byte of data that comes IN the USB connection, send it out over Bluetooth

  • For every byte of data that comes IN from the Bluetooth device, send it over USB to the computer

This way I can test that my Bluetooth devices are configured correctly and that the Arduino/Maple knows how to establish a connection.

Then I'll remove the computer from one side of the equation to make sure that my software stack is implementing the protocol correctly. That is, I'll check for proper responses on the computer from the board that is still acting as a serial data relay.

Then I'll put that first board back on the serial-relay program and make sure the other side is functioning correctly with its custom software.

Then, hopefully, everything will work!

The point of the story I am telling is that you can write a program like this:

void setup() {
  Serial.begin(57600);
  Serial1.begin(57600);
}

void loop() {
  while(Serial.available()) {
    Serial1.write(Serial.read());
  }

  while(Serial1.available()) {
    Serial.write(Serial1.read());
  }
}

I hope that helps!