Software Serial - Howto

I need to understand how I can use software serial. I simply cant get mine to work, even after using the example provided by the IDE. Any tips as to what I'm not doing ? I'm using a mega 2560 and yes, using the pins 11 for rx.

Why do you want to use software serial on a Mega? You have four real serial ports on that!

Good point, but I am using a wifi shield that requires software serial . Link of wifi shield - http://www.elecfreaks.com/wiki/index.php?title=Wifi_Shield_-_EiFi . Also, I cant get Software Serial to work on my Uno either.

but I am using a wifi shield that requires software serial

No it doesn't.
There are links on the shield that can route one of several pins to the serial.
I am not sure if software serial runs on the Mega due to the different timer configuration.

Also, I cant get Software Serial to work on my Uno either.

Then you are not doing it right. However as you haven't said how you are doing it or testing that it is working it hard to say what you are doing wrong.

Thanx for the reply.

Let me detail this for you.

#include <SoftwareSerial.h>

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

void setup()  
{
  // Open serial communications and wait for port to open:
  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());
}

I found that mySerial.Available is returned as a false.

Also I found that  not all pins on the Mega and Mega 2560 support change interrupts, 
 so only the following can be used for RX: 
 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69
TX RX.


First I need to get the software Serial working before  can start working with the Shield.

Let me detail this for you.

And what have you connected up to these software serial pins to test them?

How could a shield know whether you are using SoftwareSerial or hardware serial?

...R

And what have you connected up to these software serial pins to test them?

Nothing has been fixed to these two pins (10, 11). Any data entered into the Serial Monitor will be passed onto Serial from which it goes to mySerial, which will then be passed back to Serial so it will appear back on the Serial Monitor.

How could a shield know whether you are using SoftwareSerial or hardware serial?

Hardware Serial (using the other Serial's of the mega) can be used but that would involve me having to modify the pins of the shield so that they can be plugged into TX1 and RX1 which is my last resort.

Nothing has been fixed to these two pins (10, 11). Any data entered into the Serial Monitor will be passed onto Serial from which it goes to mySerial, which will then be passed back to Serial so it will appear back on the Serial Monitor.

Yes but before you can sat it doesn't work you have to put serial data into this pin. What are you using to put this data in? It will not respond to just putting the pins high and low yo have to have a proper asynchronous TTL level signal.

Ahh, I'm using a usb connection to the computer and the serial monitor from arduiono IDE to input the data.

Also

but that would involve me having to modify the pins of the shield so that they can be plugged into TX1 and RX1 which is my last resort.

You just put a jumper wire between the pins you want and the input and output rows of the pin select.

It works perfectly with the other hardware serial, so much thanks on that :slight_smile: However is there any way I can get Software Serial to work. It's really disturbing that i dont know why it is working ?

Anyways, Much thanks for the help

Have yo see this thread?
http://forum.arduino.cc/index.php?topic=103424.0