void setup() {
Serial.begin(9600); // serial / USB port
gtSerial.begin(9600); // software serial port
}
byte rx_byte = 0; // stores received byte
void loop() {
// check if byte available from USB port
if (Serial.available()) {
rx_byte = Serial.read();
// send a byte to the software serial port
gtSerial.write(rx_byte);
}
// check if byte available on the software serial port
if (gtSerial.available()) {
// get the byte from the software serial port
rx_byte = gtSerial.read();
Serial.write(rx_byte);
}
}
You might destroy your Arduino if you connect it to an RS-232 interface directly. The voltage levels are not compatible. You need a driver (p.e. MAX232) for that connection.
SoftwareSerial gtSerial(1,0); // Arduino RX, Arduino TX
void setup() {
Serial.begin(9600); // serial / USB port
gtSerial.begin(9600); // software serial port
}
You cannot have a SoftwareSerial on pins 0 and 1 and use the hardware serial interface (which is on the same pins) at the same time.