/*
An example of using SoftwareSerial.h per Uri Shaked's example
of a UART Example Breakout chip.
*/
#include <SoftwareSerial.h>
// Create a SoftwareSerial object
// Set RX to pin 10 and TX to pin 11
SoftwareSerial mySerial(10, 11); // RX, TX
void setup() {
// Initialize hardware serial (USB Serial Monitor) at 9600 baud
Serial.begin(115200);
Serial.println("SoftwareSerial Example");
Serial.println("Type a message and send it via Serial Monitor");
// Initialize software serial at 9600 baud
mySerial.begin(115200);
}
void loop() {
// Check if data is available from the Serial Monitor (hardware serial)
if (Serial.available()) {
// Read the incoming character from the Serial Monitor
char dataFromSerial = Serial.read();
// Send the data to the software serial device (e.g., a Bluetooth module)
mySerial.write(dataFromSerial);
// Echo the sent data back to the Serial Monitor for confirmation
Serial.print("Sent to device: ");
Serial.println(dataFromSerial);
}
// Check if data is available from the software serial device (connected device)
if (mySerial.available()) {
// Read the incoming character from the software serial device
char dataFromDevice = mySerial.read();
// Send the data to the Serial Monitor (hardware serial)
Serial.print("Received from device: ");
Serial.println(dataFromDevice);
}
// Add a short delay to avoid overwhelming the serial port
delay(100);
}