pont-uart.ino
The ATmega2560 has four hardware UARTs: perfect for a GPS, GSM module or a second microcontroller without sacrificing the USB port. The bridge copies everything between UART1 and UART2.
Hardware required
An Arduino Mega ADK Rev3 (ATmega2560 + MAX3421E USB host chip with a Type-A port; digital pin 7 is reserved for the MAX3421E reset). 2 5 V serial devices (e.g. TTL GPS + second Arduino).
Wiring
Device 1 on RX1=19/TX1=18, device 2 on RX2=17/TX2=16 (cross RX/TX), common grounds.
How it works
Every byte read on one port is written to the other, with a copy on USB to watch the traffic live. Select « Arduino Mega ADK » in the IDE. For USB host/ADK work, install the USB Host Shield 2.0 library; do not use D7. The USB-A port powers the accessory at 5 V.
Going further
Filter GPS NMEA sentences ($GPGGA prefix) instead of copying everything, for a position logger.
pont-uart.ino
// Pont serie entre Serial1 (broches 19/18) et Serial2 (17/16).
// Exemple : GPS sur UART1 -> moniteur, et module sur UART2.
void setup() {
Serial.begin(9600); // USB (debug)
Serial1.begin(9600); // UART1: RX1=19, TX1=18
Serial2.begin(9600); // UART2: RX2=17, TX2=16
Serial.println(F("Pont UART1 <-> UART2 actif"));
}
void loop() {
if (Serial1.available()) {
char c = Serial1.read();
Serial2.write(c); // appareil 1 -> appareil 2
Serial.write(c); // copie vers le moniteur
}
if (Serial2.available()) {
char c = Serial2.read();
Serial1.write(c); // appareil 2 -> appareil 1
}
}