Go Down

Topic: Help understanding simple softwareSerial example (Read 368 times) previous topic - next topic

fxmech

I am having a really hard time understanding simple serial communication specifically when it comes to having a software serial port.

I think I get it  but my tests don't give expected results so I took a big step backwards and decided to try and just get the basic softwareSerial example to work....   either it doesn't or I am just not getting it...

What exactly is this sketch meant to do?   I thought it should juggle the two printed sentences between the hardware and the software serial ports...  when it came to the hardware port it would display it on the serial monitor.

I get the initial "Goodnight moon!" once and nothing else....  Is this correct???

I an just trying to learn how to receive data through the software serial and send it out the Hardware serial...
Im not getting anything out of the soft serial ports on a nano or UNO....  please help

Code: [Select]

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3);

void setup() 
{
   Serial.begin(57600);
   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());
}

PaulS

Quote
I thought it should juggle the two printed sentences between the hardware and the software serial ports.

There is a USB to serial converter chip connected to the hardware serial pins, to which you have connected a cable that runs to the PC.

What have you connected to the software serial port?

Graynomad

You have SS on pins 2 and 3, if there is nothing connected to them you are printing into thin air.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

fxmech

Your obviously both right and that makes sense except that I thought the data was being transferred internally from port to soft port...
The reason I thought that is that if you look at the Software serial example in arduino/Learning  this is what is said about that sketch:

Quote
Software Serial Example

Arduinos have built in support for serial communication on pins 0 and 1, but what if you need more serial ports? The SoftwareSerial Library has been developed to allow serial communication to take place on the other digital pins of your Arduino, using software to replicate the functionality of the hardwired RX and TX lines. This can be extremely helpful when the need arises to communicate with two serial enabled devices, or to talk with just one device while leaving the main serial port open for debugging purpose.


In the example below, digital pins 2 and 3 on your Arduino are used as virtual RX and TX serial lines. The virtual RX pin is set up to listen for anything coming in on via the main serial line, and to then echo that data out the virtual TX line. Conversely, anything received on the virtual RX is sent out over the hardware TX.



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.




Go Up