Serial Issues

Hi all,

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:

char data;

void setup() {
 Serial.begin(9600); 
}

void loop() {
 data = Serial.read();
 Serial.print("Sending: \n");
 Serial.write(data); 
}

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.

...R

Thanks for the reply!

The hardware part is not the problem, the laser diode driving circuit can be switched by the TX pin.

What do I need to change in my code to be able to send the serial out of the TX pin?

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="";
  } 
}

Hi Zoomkat,

Thanks for the code, it compiles and I see it perfectly on the serial monitor, however, I get nothing out of my TX pin.

I've wired an LED between TX and ground for testing, so I should see this blinking. Do I need to remove the usb so it goes out the TX pin?

roboben:
I've wired an LED between TX and ground for testing

...with a current limiting resistor, I hope...

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.

I'm new to the Arduino, so take this for what it is.

I would use different pins and depending on the Arduino model use another hardware UART or use a software UART.

There is a library for software uarts; see e.g. SoftwareSerial Library

I have not used it, so can not advise further.

roboben:
What do I need to change in my code to be able to send the serial out of the TX pin?

What Arduino are you using?

On an Uno or Mega what you send with Serial.print() will appear on the Tx pin.

If you are using a Leonardo or other board with a 32U4 MCU it will not. To make stuff appear on the Tx pin you need to use Serial1.print()

...R