Using the software serial functions

Hi,

I am trying to use the software serial functions on Arduino uno board. In this case, I am using pin 10 as rx pin and pin 10 as the tx pin. Since I only have one Arduino uno board, I am trying basic test where I connect the Tx pin 11 to rx pin 10. Is that ok?

I tried connecting pin 11 to pin 10 but it is not seeing any incoming data.

In my simple code below, I send “Hello World” to the software serial port and then I look for number of bytes received. But the number of bytes received is always 0. Why it is not able to receive the data on pin 10 (pin 11 -tx is looked back to rx pin 10).

Prompt response will be great.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup() {
// put your setup code here, to run once:
//Open serial communications and wait for port to open
Serial.begin(4800);
while (!Serial) {
; //wait for serial port to connect. Needed for native USB port only
}

Serial.println(“Goodnight moon!”);

//Set the data rate for the software serial port
mySerial.begin(4800);
}

void loop() {
// put your main code here, to run repeatedly:
int BytesRcvd;
delay(5000);
BytesRcvd = mySerial.available();
mySerial.println(“Hello world”);
delay(5000);
Serial.println(BytesRcvd, HEX);
}

In this case, I am using pin 10 as rx pin and pin 10 as the tx pin

?

Please remember to use code tags when posting code

Why it is not able to receive the data on pin 10 (pin 11

Does software serial permit simultaneous output and input?

If your project needs more than one serial port then the UNO is probably not the best choice. Software Serial can do enough to use a simple GPS but it really can't do useful stuff like transmitting and receiving simultaneously.

I love the Arduino Micro. It has a USB serial for talking to the computer and a hardware Serial independent of that. I also use the Teensy series a lot. Up to 6 hardware Serial, plus the USB serial.

SoftwareSerial cannot listen and talk at the same time so loop-back from Tx to Rx is not possible.

...R

AltSoftSerial and NeoSWSerial can TX and RX at the same time. Both are available from the Arduino Library Manager in the IDE, under the menu Sketch -> Include Library -> Manage Libraries.

Can I use the hardware serial mode to do the loop back? It seems that 0 and 1 support hardware serial mode. But I do not see any good examples of it. Any input on this will be great.

No, because on the UNO, the hardware serial is attached to the USB interface.

On an Uno or Mega and a few others, hardware serial carries the same signals as the USB; they are in parallel.

So serial.print will send to both the pc an the tx pin. And serial.read will read from the pc and the rx pin.

See reply #5 for software solution or reply #3 for a hardware solution; another board that offers an additional serial port (on pins 0 and 1) with the same form factor as the Uno is the Leonardo. And there is obviously the Mega with 3 additional serial ports).

ok Thanks. In my simple application, I just need to demonstrate transmitting a text string and then receiving the text string. This is why I though that the serial port in loop back mode will be the easiest.

Since I already have on Arduino uno, I could by another Arduino Uno. So I can use the software serial mode, where I can use one Arduino uno to transmit only and the other Arduino uno to receive only. In this case software serial should work. right?

Thanks.

Yes.

No, because on the UNO, the hardware serial is attached to the USB interface.

Actually, you can use the hardware serial pins for other devices.