port1.listen(); // Switch back
void loop() // Check GPS if (gps.available()) char c = gps.read(); Serial.print(c); // Show on debug bluetooth.print(c); // Forward to Bluetooth softwareserial.h library
void loop() if (port1.available()) // Process port1 data // Show on debug bluetooth.print(c)
The classic Arduino Uno, Nano, and Mega 2560 (for its first few ports) have dedicated hardware UARTs (Universal Asynchronous Receiver-Transmitters). However, hardware UARTs are limited in number. Once you connect a GPS module, a Bluetooth module, and a debug console simultaneously, you run out of ports. a Bluetooth module
// Switch to port2 briefly port2.listen(); if (port2.available()) // Process port2 data
// Periodically check Bluetooth (non-blocking) if (bluetooth.available()) char cmd = bluetooth.read(); if (cmd == 'G') gps.listen(); // Switch back to GPS