/*
ESP32-GATEWAY Serial Demo
-------------------------
Demonstrates using a second UART on GPIO11 (TX) and GPIO13 (RX).
ESP32 Arduino package installation:
1. Open Arduino IDE → File → Preferences
2. In "Additional Boards Manager URLs" add:
https://espressif.github.io/arduino-esp32/package_esp32_index.json
3. Go to Tools → Board → Boards Manager
4. Search for "esp32" and install the package by Espressif Systems
5. Select your board under:
Tools → Board → ESP32 Arduino → "Olimex ESP32-Gateway"
Hardware connections:
- GPIO11 → TX2 (connect to RX of other device)
- GPIO13 → RX2 (connect to TX of other device)
- USB → for Serial Monitor (primary UART)
*/
#define RX2_PIN 13 // Receive pin for Serial2
#define TX2_PIN 11 // Transmit pin for Serial2
void setup() {
// Start USB serial monitor at 115200 baud
Serial.begin(115200);
while (!Serial) {
; // Wait for Serial Monitor to open
}
Serial.println("ESP32-Gateway Serial2 demo starting...");
// Initialize Serial2 on GPIO13 (RX) and GPIO11 (TX) at 9600 baud
Serial2.begin(9600, SERIAL_8N1, RX2_PIN, TX2_PIN);
Serial.println("Serial2 initialized on GPIO11 (TX) / GPIO13 (RX)");
}
void loop() {
// Send test message periodically via Serial2
Serial2.println("Hello from ESP32-Gateway Serial2!");
// If data is received on Serial2, display it on the USB serial monitor
if (Serial2.available()) {
String incoming = Serial2.readStringUntil('\n');
Serial.print("Received on Serial2: ");
Serial.println(incoming);
}
// Echo any text entered in the Serial Monitor to Serial2
if (Serial.available()) {
String input = Serial.readStringUntil('\n');
Serial2.print("Echo from USB: ");
Serial2.println(input);
}
delay(2000); // Delay 2 seconds between transmissions
}