Getting Arduino SoftSerial to work

HI,

I tried the example listed for softwareserial on the latest arduino 1.0.3. and can not get it to work. I have a arduino uno r3 board. Here is the code copied from the arduoino example which does not work. I only get “goodnight moon”. on the arduino terminal screen.

Thank you.

#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());
}

What device communicating at 4800bps do you have connected to pins 10 and 11?

Hi,

Thank you for writing back. I do not have anything connected to pins 10 or 11. I assumed the probram would run on its own. I am thinking that it should print “Hello World” to the arduino terminal screen via mySerial and it doesn’t seem to do this. Just can’t get it working after hours of trying. Any help would b appreciated.

Thank you,

Scott

Softwareserial is for serial communication using non-standard physical pins and is really useful in connecting multiple serial devices to your arduino. In the loop function, that program sends what was received from the serial and softserial port to the other. If you type something into the serial port (open the serial monitor in Arduino), it sends that to the softserial port. If you connected two arduinos to the serial monitor in Arduino and connected the softserial port (10 and 11) of the arduino running this code to the serial port (1 and 0) of the other, you would see this working. This would also work with an ftdi-usb replacing the other arduino.

Thank you! I will try it.

Scott

I notice in your other thread that you are using the Mega. That has 4 hardware UARTS. So, you shouldn’t need to use SoftwareSerial. Just use one of the other hardware serials.