I've been searching exhaustively about this, but can't find a solid example that works.
Here's my setup:
I want to use a computer with a serial monitor to type a string to my arduino, store the string (let's assume "Hello World"), then transmit that string using a laser module via the arduino's TX pin.
An arduino on the receiving end has a photodiode on the RX pin, and will print this string to the serial monitor of a second computer.
So my question is, in order to make the transmission side work, do I need to use software serial?
Here is the basic serial code I was starting with, where data would be "hello world" or whatever message comes from the serial monitor:
If I was using infra-red I would apply the system in this Thread. You will see that it uses a 38kHz carrier frequency to make the system more reliable.
I don't know anything about lasers so I don't know if it is necessary to use a carrier frequency. Assuming it is not, then if your laser beam can be turned on and off by the signal on the TX pin there should be no need to use SoftwareSerial. However having a separate (SoftwareSerial) port for sending the data makes it much easier to debug code with messages to the Serial Monitor using Hardware Serial.
If you decide to use SoftwareSerial get it working at 9600 baud before trying anything faster.
Very simple example of sending a string of characters from the serial monitor, capturing the characters, and then sending the characters back out the arduino tx.
//zoomkat 6-29-14 Simple serial echo test
//type or paste text in serial monitor and send
String readString;
void setup() {
Serial.begin(9600);
Serial.println("Simple serial echo test"); // so I can keep track of what is loaded
}
void loop() {
while (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the String readString
delay(2); //slow looping to allow buffer to fill with next character
}
if (readString.length() >0) {
Serial.println(readString); //so you can see the captured String
readString="";
}
}
Thanks for the code, it compiles and I see it perfectly on the serial monitor, however, I get nothing out of my TX pin.
If you see something on the serial monitor, then something is coming out of the arduino tx pin. Wiring an LED to the tx pin is probably not a good idea as it could disrupt the serial operation.