Software Serial Question

I have a beaconing device that transmits data and also sends it as text to a serial port at 19200 baud, 8N1. I can read this using an RS-232 to USB convertor, or an old-fashioned serial port. I am trying to read it with an Arduino, using Software Serial. The code is as follows (copied from the demo):

/*
Software serial test
Receives from software serial, sends to hardware serial.

  • RX is digital pin 10 (connect to TX of other device)
  • TX is digital pin 11 (connect to RX of other device)

*/

#include <SoftwareSerial.h>

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

void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(19200);
Serial.println(“Goodnight moon!”);

// set the data rate for the SoftwareSerial port
mySerial.begin(19200);
}

void loop() // run over and over
{
if (mySerial.available())
Serial.write(mySerial.read());
}

When I run this, I get the same string of characters each time the device beacons:

Z×vÕõUÖ6Ö}]]]EµÝÕu?u;?jÝÕm?u[ Û?ëÖVV¶?övÖ6Öl6ÖövVV6ö5¶v¶öööÖ}}{«?ëVëZ×vÕõUÖ6Ö}]]]EµÝÕu?u;?jÝÕm?u[ Û?ëÖV¶?övÖ6Öl6ÖövVV6ö5¶v¶ööö?m5eºê:úûêÚJ
ë}

So it is sending the data, but it is shifted in some way. Baud is correct. Are there other parameters I need to set, or what else am I missing here? Thanks for any help.

modernhistorian:   Serial.println();

Does this "Goodnight moon!" message come out correctly? What is the beacon message supposed to look like, if it were being echoed correctly?

gardner:

modernhistorian:   Serial.println();

Does this "Goodnight moon!" message come out correctly? What is the beacon message supposed to look like, if it were being echoed correctly?

"Goodnight moon!" prints correctly. Serial and mySerial are both set to 19200, as is the terminal program. Pins 10 and 11 are the only ones connected to the device.

A good question. I stripped the beacon to send a shortened and unchanging test. Below are the results on a terminal program and through Arduino's software serial:

KD0TYP-1>APTT4,WIDE1-1,WIDE2-1:/010000z3849.92N/10455.86W>000/000/A=008462

Z×vÕõUÖ6Ö}]]]EµÝÕu?u;?jÝÕm?u[ ûëûööö¶?övÖ6Öl6ÖövVV6ö65ööööööÖ

There are 74 characters in the first text, but 56 in the second. Any ideas on this?

If you send the same message several times, is the received garbage identical every time?

There are 74 characters in the first text, but 56 in the second. Any ideas on this?

A couple possibilities. Mismatched baud rates can cause improper receiving of data, failure to properly convert rs232 to TTL can result in garbage data, and some of the improperly received bytes may be interpreted as non printable bytes.

zoomkat: failure to properly convert rs232 to TTL can result in garbage data

Is it possible you have the logic levels of your serial device inverted? Software serial used to have an option to invert the sense of the TTL signal, but I don't see that in the current library.

You are pushing it to handle fast baud rates with SoftwareSerial while at the same time processing interrupts for HardwareSerial. One interrupt is likely to slow down the other long enough to miss a bit. The hardware has a two-character buffer to handle that. The software doesn't.

Once you miss even a single bit it is likely to think the next zero bit is a start bit, and then mis-process one or even many bytes.

Try reading the entire message before resending any of it.

Even if this doesn't suit your intended application it will be good for debugging.

...R

Try swapping the serials, (you need some additional HW to connect to PC - for testing another Arduino might work)

use hardware serial to read from the beacon and write it with software serial

Pins 10 and 11 are the only ones connected to the device.

Beside ground, you mean, right?