/* Program 4-5: Serial1 loopback on Arduino Mega * * Connect a wire between pin PD2 (RxD1) and pin PD3 (TxD1) of * the Mega */ void setup() { Serial.begin(9600); /* initialize serial and set the Baud rate to 9600 */ Serial1.begin(115200); /* initialize serial1 and set the Baud rate to 9600 */ } void loop() { char c; if(Serial.available()) { /* if a char is available */ c = Serial.read(); /* read it */ Serial1.write(c); /* and write it to Serial1 */ } if(Serial1.available()) { /* if a char is available */ c = Serial1.read(); /* read it */ Serial.write(c); /* and write it to Serial */ } }