I have been working on a project that needs to get data from two different serial ports. I am using one device on the native serial pins and I am not having any issues with that device. To be able to get data from the second serial device I am trying to use a software serial setup. (I have tried both the softwareserial and the AltSoftSerial libraries with the same results). I can tell that the data is being received but the serial data is being "scrambled" for lack of a better word. What I am seeing resembles what I would expect to see in a telnet program if baud rates were not the same. I have verified baud rates on all devices and they are correct.
For example: Data sent to Arduino: "Hello World from TXTlandia..."
Data "received" by Arduino (based on serial.print): ú
e'7¿3e!%¿WOW'=#7-=£££åë
The result is constant... ie send the same string and get the same output every time. What simple step am I missing or mis-understanding that I can't get the Arduino to properly read the serial data?
Below is my current code:
#include <AltSoftSerial.h>
/*
This project will allow a service technician to field test
print signals going out to SATO printers.
*/
#define DataStatus 13
//Software Serial Port: RX = 8, TX = 9)
//const byte rx = 8; //Brown
//const byte tx = 9; //Blue
AltSoftSerial pntData; //(rx, tx)
String DataIn;
const byte numChars = 32;
char receivedChars[numChars];
boolean newData = false;
void setup() {
// put your setup code here, to run once:
Serial.begin(19200);
while (!Serial) {}
pinMode(DataStatus, OUTPUT);
pntData.begin(19200);
}
void loop() {
// put your main code here, to run repeatedly:
while (pntData.available()==0){
Serial.println("No Data Availible...");
digitalWrite(DataStatus, HIGH);
delay(250);
digitalWrite(DataStatus, LOW);
delay(250);
}
recvData();
}
void recvData() {
static byte ndx = 0;
char endMarker = '\n';
char rc;
while (pntData.available() > 0 && newData == false) {
rc = pntData.read();
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
}
}
DataIn = receivedChars;
showNewData();
}
void showNewData() {
if (newData == true) {
Serial.print("Data Received: ");
Serial.println(DataIn);
newData = false;
}
}