Unable to get SoftwareSerialExample to run

I have been attempting to get the SoftwareSerialExample to run on a Uno. The program downloads ok but when I look at the output on the serial monitor the output consists of

yyyyyyyyGoodnight Moon!
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy..........(the y is ascci 255 ie a 'y' with 2 dots on top and is being transmitted continuously)

#include <SoftwareSerial.h>

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

void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(57600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}

Serial.println("Goodnight moon!");

// set the data rate for the SoftwareSerial port
mySerial.begin(4800);
mySerial.println("Hello, world?");
}

void loop() // run over and over
{
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
}

I have wired SoftwareSerial pin 10 to Serial TX and SoftwareSerial pin 11 to Serial RX which I assume is correct. This problem has appeared in previous posts but I couldn't find an obvious solution. It seems that data is not being correctly written to the SoftwareSerial port.
I have downloaded the latest Arduino IDE.
All help greatly appreciated!
Malcolm.

How is it wired? Did you make an infinite loop?

This example is supposed to be used to put the Arduino in between two devices that communicate at different speeds. You don't connect the Arduino to itself.

Thanks for the reply MorganS, yes I had connected the 2 serial ports, I have since looked at the Arduino Learning page of the Software Serial example and it shows just one Arduino board and no connections except the USB.
My output to the serial monitor now is a single line of text "Goodnight moon!", not the alternating text I expect of "Goodnight moon!"/"Hello, world?" as the 2 lines of text are shifted between the 2 serial ports.

That page is half baked.

http://arduino.cc/en/Tutorial/SoftwareSerialExample

Hardware Required

Arduino Board

Circuit

There is no circuit for this example. Make sure that your Arduino is attached to your computer via USB to enable serial communication.

/*
  Software serial multple serial test
 
 Receives from the hardware serial, sends to software serial.
 Receives from software serial, sends to hardware serial.
 
 The circuit:
 * RX is digital pin 10 (connect to TX of other device)
 * TX is digital pin 11 (connect to RX of other device)

Notice:

  • RX is digital pin 10 (connect to TX of other device)
  • TX is digital pin 11 (connect to RX of other device)

You need another 5V TTL serial device or circuit-made compatible to connect to.
You could even make your own breadboard Duino, program it and connect to that.

Well, not totally.... you could drive a led with TX and maybe hook RX up to a light sensor that you feed flashing light to, maybe even make a led or laser modem but that still needs another device.

Whatever you connect to pins 0 and 1 of an UNO that is plugged into USB goes straight to USB.

What have you connected to pins 10 and 11?

If there is nothing connected to them then there is nothing for SoftwareSerial to do.

...R

This doesn't work, SoftSerial is crap for doing 2-way comms, so forget it. Maybe one day someone will figure out how to write it correctly.

void loop() // run over and over
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}

If you really need to do this, get a board with more than one hardware UART, like a mega2560 or a Bobuino with 1284 chip.

In what way is it crap? There are limitations for SoftwareSerial but the basic example shown above does work and you can use it in 'real' projects.

It never worked for me. Try it again. OTOH, maybe someone fixed SS recently. OTOH, every other day, someone posts around here that it doesn't work. Maybe I just live in the SS Twilight Zone.

oric_dan:
This doesn't work, SoftSerial is crap for doing 2-way comms, so forget it. Maybe one day someone will figure out how to write it correctly.

void loop() // run over and over

{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}



If you really need to do this, get a board with more than one hardware UART, like a mega2560 or a Bobuino with 1284 chip.

I've used it with two UNO's, both USB connected to the same PC. It works.
The fastest I got it to work was 57600 though.

I should mention that I didn't use 10 & 11 but 2 & 3.
Seriously, I've helped a few people get projects working that used versions of software serial going back to IDE 0022.

Maybe "I" need to try it again, duh. BTW, did you just enter characters from the keyboards, or try to send longish files? Did you use the exact code shown in the quote, or something else?

And reference your signature line, Nick also tried the same exact code in a thread some time ago, and it didn't work for him either. But that was then. Maybe there are two different SS Twilight Zones around here.