// ESP32 Sender - Sends "hello" every 5 seconds and receives "ciao"
#include <Arduino.h>
// Define UART pins
#define RX_PIN 16 // GPIO16 for UART2 RX
#define TX_PIN 17 // GPIO17 for UART2 TX
void setup() {
// Initialize Serial Monitor for debugging
Serial.begin(115200);
// Initialize UART2 for communication with the second ESP32
Serial2.begin(115200, SERIAL_8N1, RX_PIN, TX_PIN);
}
void loop() {
// Check if data is available from the other ESP32
if (Serial.available()) {
// Read the incoming message
String message = Serial.readStringUntil('\n');
message.trim(); // Remove any whitespace or newline characters
// Print received message
Serial.print(message);
Serial2.print(message);
}
}