Don't understand NewSoftSerial example...

Hi All...

I'm trying to understand the NewSoftSerial example...

#include <NewSoftSerial.h>

NewSoftSerial mySerial(2, 3);

void setup()  
{
  Serial.begin(57600);
  Serial.println("Goodnight moon!");

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

void loop()                     // run over and over again
{

  if (mySerial.available()) {
      Serial.print((char)mySerial.read());
  }
  if (Serial.available()) {
      mySerial.print((char)Serial.read());
  }
}

I see tha it instansiates an instance of NewSoftSerial. Okay, simple enough.

Why in the setup function is he using the standard Serial library to set the port speed and output some text?

Then, why does he use NewSoftSerial to change the baud rate?

When i compile and run this example on my Uno, I open a terminal program, set it to the correct com port, then set the speed to 57600 and I see the Goodnight Moon text. But then I don't see Hello World. If I set my baud rate to 4800 I only see a little junk.

Can some kind soul please explain what this app is supposed to do?

Thanks...

Looks like NewSoftSerial is setting up a serial link on pins 2 and 3 to communicate with another device, and using the standard serial port to let you know what is happening. In order to see the Hello World, you need to connect another serial device to pins 2 and 3 and set the baud rate to 4800 on that link.

edit: Looking at the constructor in the header file, pin 2 is the receive (Rx) pin, and pin 3 is the transmit (Tx) pin.

The goodnight moon example uses 2 serial ports, the standard hardware one connected to the Serial Monitor. The newsoftserial port is intended to be connected to another arduino running the same sketch and they have a conversation of sorts.

Oh okay, thanks. Is there a way to use NewSoftSerial with the standard serial port?

I looked for docs on it, no joy...

Okay so looking through the code, I see that there is only one constructor and it wants pin numbers for the IO. So does that mean I need to know which pins are connected to the UART, or does it mean I can only use this library for serial IO on the digital input/output pins?

Thanks...

Got it. If I instansiate NewSoftSerial with pins 0 and 1 it uses the system port. Maybe I'll add those values as defaults on the constructor, or else add a default constructor to my copy of the library.

Thanks everyone!