SoftwareSerial enhancements needed

Hi all,

I'm currently having problems with the SoftwareSerial library. Currently when you read with the software serial it will break (stop) in the code until there is actually something to read. Is there anyway around this ? Can something be implemented like the Serial.available() method ?

Any thoughts on this or ways to get around it ?

Mark

Check out this thread.

-j

Beautiful, thanks so much.

Was just trying out that NewSoftwareSerial and I'm getting worse results than before. Any other ideas out there ?

Mark

May we see the code you're having trouble with?

Mikal

Hi there,

To receive, I am using the example program:

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

  // set the data rate for the NewSoftSerial port
  mySerial.begin(4800);
}

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

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

My sending code is simply this:

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

  // set the data rate for the NewSoftSerial port
  mySerial.begin(4800);
}

void loop()                     // run over and over again
{
    mySerial.print("HI");
    delay(1000);
    mySerial.print("BYE");
    delay(1000);
}

When I use the SoftwareSerial it seems to work pretty good with the exception of being able to to use the method .available() to continue the arduino loop even if no transmission is incoming. When I use the NewSoftSerial library, it receives to much garage in between each transmission I don’t understand why. And not only does it receive a lot of garbage but my “HI” and “BYE” rarely come through properly.

Any thoughts ?

Mark

Mark, I gather you have two Arduinos connected back to back? Are the grounds on each wired together? They should be. It they are, then please send more details about your setup. This simple pair of sketches would seem to be a classic usage. It should work fine.

Try sending a conversation initiation character when your transmitting, then reading that character at the other end so you know what order the bytes are coming in.

That code probably won't work orderly over normal serial, let alone SS.

@John_Ryan,

Why do you say that? In my opinion this should work perfectly with NewSoftSerial, HardwareSerial, or any serial library. Why do you need to "know what order the bytes are coming in"? The receiver simply prints them as they arrive, and that's this order: H, I, B, Y, E. This sketch is a very simple version of the kind of code the various [soft] serial libraries deal with all the time.

Mikal

Hey guys,

Thanks for the responses. Ok let me start answering some of your questions... No my arduinos are not 'wired' together because I'm using wireless communications with the NewSoftSerial library. I definitely don't need an initiation character at this point, the problem is beyond that.

The weird thing is that the SoftSerial library works just fine for me. I send characters and I receive them just how they are sent. The second I switch over to either the AFSoftSerial or the NewSoftSerial libraries, it keeps receiving garbage (noise). Some characters get through but not nearly what it should be doing.

Any more thoughts ? I would go back to using SoftSerial but I really need that available() method because if there are no data coming in, the loop on the arduino just halts until there are data coming in.

Mark

Hmm… I think I need more data before I can make a guess about what is going wrong. Perhaps a wiring diagram?

Mikal

I don't think a wiring diagram will help. Like I said, it I'm receiving what I should be when using the SoftSerial library but when I switch libraries I get mostly garbage but some 'good' data gets through. Both test cases use the same wiring setup.

mark

Well, it certainly is your call. But turning that logic on its head, NewSoftSerial and AFSoftSerial work fine with a multitude of hardware, but when we plug in yours they fail. That “proves” that the problem isn’t in the SW, right? :slight_smile:

As a software developer, I would NEVER rule out the fact that there could be something wrong with the software. It could be a combination of both but the fact of the matter is that my current wiring setup works just fine with the SoftSerial library so I wouldn't know how to debug my wiring setup when it works just fine with another library.

Mark

OK I was just tinkering around and came across something odd. I am transmitting with the NewSoftSerial library and I tried receiving with the same library with no luck (getting wrong data) so then I tried switching to the old SoftSerial library and I get the right data (with lots of noise in between each packet).

Any thoughts ? This is boggling my brain.

Mark

I finally figured some stuff out to anybody who is interested. I went back to using the original software serial library and got around my problem of waiting for any incoming data by just doing a simple check on the pin that connects to the receiver.

I am now checking using this

if(digitalRead(rxPin)==LOW){
     mySerial.read();
}

The old software serial library is working great for me and by checking the pin manually, the arduino doesn't stall anymore waiting for incoming data.

Mark