Trouble receiving Serial data correctly from two serial ports

Hi, I am using the Due for the first time and am having a problem with achieving dual serial communication

I basically have two sensor units each has a NANO receiving analog data from 5 sensors each and sending it out via serial (tx pin)

At the receiving end I have a single DUE receiving data from sensor unit A on serial port #2 and data from Sensor unit B on serial port #3
I am also using the main Serial port on the DUE to serial print to the Serial monitor so I can see what is happening.

When I read the 5 analog sensor values (0-1024) they are processed by the arduino Nano (map, constrain, etc) then the final values are sent out the serial port with a letter prefixing the value (sensor 1 gets Serial.print (‘A’); Serial.println(value);, sensor two gets a ‘B’, etc)

When the data is received by the DUE it comes in on two seperate ports.

Here is the TX sketch:

//limits for sensor range
int digit1UL=330;
int digit1LL=330;
int digit2UL=330;
int digit2LL=330;
int digit3UL=330;
int digit3LL=330;
int digit4UL=330;
int digit4LL=330;
int digit5UL=330;
int digit5LL=330;

int del=(100); // delay if needed to keep serial from overflowing
int aux; //aux switch value (on/off)


void setup(){
  Serial.begin(9600);
  pinMode(3, INPUT); //Lower Limit
  pinMode(4, INPUT);// Upper limit
  pinMode(6, INPUT);// Aux switch
}

void loop(){
  // read all sensors
  int buttonA=digitalRead(3);// Upper limit
  int buttonB=digitalRead(4);//Lower limit
  int buttonC=digitalRead(6);//Aux switch
  int thumbSensorReading1 = analogRead(A0);
  int indexSensorReading2 = analogRead(A1);
  int middleSensorReading3 = analogRead(A2);
  int ringSensorReading4 = analogRead(A3);
  int pinkySensorReading5 = analogRead(A4);

  //calibrate unit
  if (buttonA==HIGH && buttonB==LOW){ //Button A pressed = high limit set
    digit1UL=thumbSensorReading1;
    digit2UL=indexSensorReading2;
    digit3UL=middleSensorReading3;
    digit4UL=ringSensorReading4;
    digit5UL=pinkySensorReading5;
  }

  if (buttonB==HIGH && buttonA==LOW){ //Button B pressed = low limit set
    digit1LL=thumbSensorReading1;
    digit2LL=indexSensorReading2;
    digit3LL=middleSensorReading3;
    digit4LL=ringSensorReading4;
    digit5LL=pinkySensorReading5;
  }

  if (buttonC==HIGH ) //Button C pressed = Aux ON
    aux=1024; 
  else aux=0;


  //modify sensor values based on calibration parameters
  int adjustedReading1=map(thumbSensorReading1,digit1LL,digit1UL,1024,0);
  adjustedReading1=constrain(adjustedReading1,0,1024);
  int adjustedReading2=map(indexSensorReading2,digit2LL,digit2UL,1024,0);
  adjustedReading2=constrain(adjustedReading2,0,1024);
  int adjustedReading3=map(middleSensorReading3,digit3LL,digit3UL,1024,0);
  adjustedReading3=constrain(adjustedReading3,0,1024);
  int adjustedReading4=map(ringSensorReading4,digit4LL,digit4UL,1024,0);
  adjustedReading4=constrain(adjustedReading4,0,1024);
  int adjustedReading5=map(pinkySensorReading5,digit5LL,digit5UL,1024,0);
  adjustedReading5=constrain(adjustedReading5,0,1024);


  //OUTPUT DATA TO SERIAL PORT
  Serial.print('A'); //Header character to let receiver know what sensor the value received is associated with
  Serial.println(adjustedReading1); // send actual sensor value
  delay(del); //  here in case a delay is needed
  Serial.print('B');
  Serial.println(adjustedReading2);
  delay(del);
  Serial.print('C');
  Serial.println(adjustedReading3);
  delay(del);
  Serial.print('D');
  Serial.println(adjustedReading4);
  delay(del);
  Serial.print('E');
  Serial.println(adjustedReading5);
  delay(del);
  Serial.print('F'); // this is the auxillary switch (on or off)
  Serial.println(aux);
  delay(del);
}

Here is my receiving sketch so far (doesn’t do anything yet except receive data and put it on the screen):

char code2;  //variable to store lettter for sensor unit A
char code3;  //variable to store lettter for Sensor unit B
int value2;  //variable to store integer value for sensor unit A
int value3;  //variable to store integer value for Sensor unit B
int del=0;  //delay value if needed


void setup() {
  Serial.begin(9600);  //initialize serial for displaying data to screen
  Serial2.begin(9600); //initialize serial for receiving Sensor unit A data
  Serial3.begin(9600); //initialize serial for receiving Sensor unit B data
}

void loop() 
{
 readSerial2(); //read serial port function Sensor unit A
 readSerial3(); //read serial port function Sensor unit B

  if (code2=='A')   {
    Serial.print("2value A: "); 
    Serial.println(value2);
  }
  if (code2=='B')   {
    Serial.print("2value B: "); 
    Serial.println(value2);
  }    
  if (code2=='C')   {
    Serial.print("2value C: "); 
    Serial.println(value2);
  }
  if (code2=='D')   {
    Serial.print("2value D: "); 
    Serial.println(value2);
  } 
  if (code2=='E')   {
    Serial.print("2value E: "); 
    Serial.println(value2);
  }
  if (code2=='F')   {
    Serial.print("2value F: "); 
    Serial.println(value2);
  }


  if (code3=='A')   {
    Serial.print("3value A: "); 
    Serial.println(value3);
  }
  if (code3=='B')   {
    Serial.print("3value B: "); 
    Serial.println(value3);
  }      
  if (code3=='C')   {
    Serial.print("3value C: "); 
    Serial.println(value3);
  }
  if (code3=='D')   {
    Serial.print("3value D: "); 
    Serial.println(value3);
  } 
  if (code3=='E')   {
    Serial.print("3value E: "); 
    Serial.println(value3);
  }
  if (code3=='F')   {
    Serial.print("3value F: "); 
    Serial.println(value3);
  }

  delay(del); //delay if needed

}

void readSerial2(){  //read serial port function for Sensor unit A data IN
  while (Serial2.available() > 0) { //wait for something to come through serial port
    int a = Serial2.peek(); //peek into data to see if its a letter or number
    if (a<48 || a>57) code2=Serial2.read(); //if its a value other than 0-9 read it and load it into text variable
   else value2= Serial2.parseInt(); //if not then it must be a number so parse it and save it to integer variable
  }
}

void readSerial3(){  //read serial port function for Sensor unit B data IN
  while (Serial3.available() > 0) { //wait for something to come through serial port
    int a = Serial3.peek(); //peek into data to see if its a letter or number
    if (a<48 || a>57) code3=Serial3.read(); //if its a value other than 0-9 read it and load it into text variable
   else value3= Serial3.parseInt(); //if not then it must be a number so parse it and save it to integer variable
  }
}

the results have Sensor A showing sensor F values so its like its reading the number first and not the letter so it assigns the value to the incorrect letter.

Data stream looks like this:
2value A: 0
3value E: 1024
2value B: 1023
3value F: 1024
2value C: 1024
3value A: 0
2value D: 1024
3value B: 1024
2value E: 1024
3value C: 1024
2value F: 1023
3value D: 1024
2value A: 0

2value F: should be the 0 value not 2 valueA…
Is there a better way to read data via two serial ports simultaneously?
Also any ideas why my data is shifted from the identifier character?

Your code has some unusual aspects, for one thing you aren’t clearing code2 and code3 after detecting they have changed. Better read this:

http://www.gammon.com.au/serial

    if (a<48 || a>57) code2=Serial2.read(); //if its a value other than 0-9 read it and load it into text variable

Just say this, if this is what you mean:

    if (a < '0' || a > '9') 
      code2 = Serial2.read(); // if it's a value other than 0-9 read it and load it into text variable

A few more spaces wouldn’t hurt either.

http://www.gammon.com.au/forum/?id=12153#style

Nick,

I visited your blog and tried my program using your serial example and it worked flawlessly!!!
I was able to bump up the baud from 9600 to 57600 and also remove a big delay (100) that I had added to try to help the communication when using my code.

The problem I still have is that when I try reading from two seperate Serial ports I get bad data:

here is the code:

int del=0;  //delay value if needed
typedef enum {  NONE, GOT_A, GOT_B, GOT_C, GOT_D, GOT_E, GOT_F, GOT_G, GOT_H, GOT_I, GOT_J, GOT_K, GOT_L} states;
states state = NONE;
unsigned int currentValue;

void setup() {
  Serial.begin(115200);  //initialize serial for displaying data to screen
  Serial2.begin(57600); //initialize serial for receiving Sensor unit A data
  Serial3.begin(57600); //initialize serial for receiving Sensor unit B data
}

void loop() 
{
  if (Serial2.available ())
    processIncomingByte (Serial2.read ());
      if (Serial3.available ())
    processIncomingByte (Serial3.read ());

  delay(del); //delay if needed

}


void processA (const unsigned int value)
{
  Serial.print ("A = ");
  Serial.println (value);
}

void processB (const unsigned int value)
{
   Serial.print ("B = ");
  Serial.println (value);
} 

void processC (const unsigned int value)
{
   Serial.print ("C = ");
  Serial.println (value);  
} 

void processD (const unsigned int value)
{
  Serial.print ("D = ");
  Serial.println (value);
} 

void processE (const unsigned int value)
{
  Serial.print ("E = ");
  Serial.println (value);
} 

void processF (const unsigned int value)
{
  Serial.print ("F = ");
  Serial.println (value);
} 

void processG (const unsigned int value)
{
  Serial.print ("G = ");
  Serial.println (value);
}

void processH (const unsigned int value)
{
   Serial.print ("H = ");
  Serial.println (value);
} 

void processI (const unsigned int value)
{
   Serial.print ("I = ");
  Serial.println (value);  
} 

void processJ (const unsigned int value)
{
  Serial.print ("J = ");
  Serial.println (value);
} 

void processK (const unsigned int value)
{
  Serial.print ("K = ");
  Serial.println (value);
} 

void processL (const unsigned int value)
{
  Serial.print ("L = ");
  Serial.println (value);
}
void handlePreviousState ()
{
  switch (state)
  {
  case GOT_A:
    processA (currentValue);
    break;
  case GOT_B:
    processB (currentValue);
    break;
  case GOT_C:
    processC (currentValue);
    break;
      case GOT_D:
    processD (currentValue);
    break;
      case GOT_E:
    processE (currentValue);
    break;
      case GOT_F:
    processF (currentValue);
    break;
      case GOT_G:
    processG (currentValue);
    break;
  case GOT_H:
    processH (currentValue);
    break;
  case GOT_I:
    processI (currentValue);
    break;
      case GOT_J:
    processJ (currentValue);
    break;
      case GOT_K:
    processK (currentValue);
    break;
      case GOT_L:
    processL (currentValue);
    break;
  }  // end of switch  

  currentValue = 0; 
}  // end of handlePreviousState

void processIncomingByte (const byte c)
{
  if (isdigit (c))
  {
    currentValue *= 10;
    currentValue += c - '0';
  }  // end of digit
  else 
  {

    // The end of the number signals a state change
    handlePreviousState ();

    // set the new state, if we recognize it
    switch (c)
    {
    case 'A':
      state = GOT_A;
      break;
    case 'B':
      state = GOT_B;
      break;
    case 'C':
      state = GOT_C;
      break;
          case 'D':
      state = GOT_D;
      break;
    case 'E':
      state = GOT_E;
      break;
    case 'F':
      state = GOT_F;
      break;
          case 'G':
      state = GOT_G;
      break;
    case 'H':
      state = GOT_H;
      break;
    case 'I':
      state = GOT_I;
      break;
          case 'J':
      state = GOT_J;
      break;
    case 'K':
      state = GOT_K;
      break;
    case 'L':
      state = GOT_L;
      break;
    default:
      state = NONE;
      break;
    }  // end of switch on incoming byte
  } // end of not digit  
  
} // end of processIncomingByte

I created headers A-F for sensor pack 1 (serial port 2) and headers G-L for the second sensor pack broadcasting through Serial port 3.

if I only read from one I get data like this:
A = 1024
B = 1024
C = 1024
D = 1024
E = 1024
F = 0
A = 1024
B = 1024
C = 1024
D = 1024
E = 1024
F = 0

if I connect both sensor packs I get:

D = 2140
H = 0
F = 2
A = 0
B = 0
K = 12042
C = 0
L = 2
G = 0
H = 0
E = 1
I = 0
F = 2
A = 0
J = 11002244
B = 0
K = 4
C = 0

Any ideas???

Its soooo close :frowning:
I thought maybe I need to double up all of the functions and rename them so theres a processIncomingBytesA() and processIncomingBytesB()????.... is this the way to go???

I thought maybe I need to double up all of the functions and rename them so theres a processIncomingBytesA() and processIncomingBytesB()????.... is this the way to go???

Yes as it stands the code is mixing up the two streams.

  delay(del); //delay if needed

Sit on your ass doing nothing, waiting for the buffers to overflow. What a great idea. NOT!

fxmech:
Nick,

I visited your blog and tried my program using your serial example and it worked flawlessly!!!
I was able to bump up the baud from 9600 to 57600 and also remove a big delay (100) that I had added to try to help the communication when using my code.

That's good.


I'm puzzled about these functions:

void processA (const unsigned int value)
{
  Serial.print ("A = ");
  Serial.println (value);
}

void processB (const unsigned int value)
{
  Serial.print ("B = ");
  Serial.println (value);
} 

void processC (const unsigned int value)
{
  Serial.print ("C = ");
  Serial.println (value);  
}

They all do such similar things, do you really need them all?

I thought maybe I need to double up all of the functions and rename them so theres a processIncomingBytesA() and processIncomingBytesB()????.... is this the way to go???

That would be one way, as Grumpy_Mike said, you are basically mixing the data from both streams together.

Do you need all these state machine states?

Copying and pasting (and renaming) is one way, it sounds a bit brute-force to me. What if you ever need 3 serial inputs?

The modified code below modifies your existing functions so pass down the current state and current value, so that at least the confusion about the two ports should be less:

int del=0;  //delay value if needed
typedef enum {  
  NONE, GOT_A, GOT_B, GOT_C, GOT_D, GOT_E, GOT_F, GOT_G, GOT_H, GOT_I, GOT_J, GOT_K, GOT_L} 
states;

states stateA = NONE;
states stateB = NONE;
unsigned int currentValueA;
unsigned int currentValueB;

void setup() {
  Serial.begin(115200);  //initialize serial for displaying data to screen
  Serial2.begin(57600); //initialize serial for receiving Sensor unit A data
  Serial3.begin(57600); //initialize serial for receiving Sensor unit B data
}

// function prototypes
void processIncomingByte (const byte c, states & state, unsigned int & currentValue);
void handlePreviousState (states & state, unsigned int & currentValue);

void loop() 
{
  if (Serial2.available ())
    processIncomingByte (Serial2.read (), stateA, currentValueA);
  if (Serial3.available ())
    processIncomingByte (Serial3.read (),  stateB, currentValueB);

  delay(del); //delay if needed

}


void processA (const unsigned int value)
{
  Serial.print ("A = ");
  Serial.println (value);
}

void processB (const unsigned int value)
{
  Serial.print ("B = ");
  Serial.println (value);
} 

void processC (const unsigned int value)
{
  Serial.print ("C = ");
  Serial.println (value);  
} 

void processD (const unsigned int value)
{
  Serial.print ("D = ");
  Serial.println (value);
} 

void processE (const unsigned int value)
{
  Serial.print ("E = ");
  Serial.println (value);
} 

void processF (const unsigned int value)
{
  Serial.print ("F = ");
  Serial.println (value);
} 

void processG (const unsigned int value)
{
  Serial.print ("G = ");
  Serial.println (value);
}

void processH (const unsigned int value)
{
  Serial.print ("H = ");
  Serial.println (value);
} 

void processI (const unsigned int value)
{
  Serial.print ("I = ");
  Serial.println (value);  
} 

void processJ (const unsigned int value)
{
  Serial.print ("J = ");
  Serial.println (value);
} 

void processK (const unsigned int value)
{
  Serial.print ("K = ");
  Serial.println (value);
} 

void processL (const unsigned int value)
{
  Serial.print ("L = ");
  Serial.println (value);
}

void handlePreviousState (states & state, unsigned int & currentValue)
{
  switch (state)
  {
  case GOT_A:
    processA (currentValue);
    break;
  case GOT_B:
    processB (currentValue);
    break;
  case GOT_C:
    processC (currentValue);
    break;
  case GOT_D:
    processD (currentValue);
    break;
  case GOT_E:
    processE (currentValue);
    break;
  case GOT_F:
    processF (currentValue);
    break;
  case GOT_G:
    processG (currentValue);
    break;
  case GOT_H:
    processH (currentValue);
    break;
  case GOT_I:
    processI (currentValue);
    break;
  case GOT_J:
    processJ (currentValue);
    break;
  case GOT_K:
    processK (currentValue);
    break;
  case GOT_L:
    processL (currentValue);
    break;
  }  // end of switch  

  currentValue = 0; 
}  // end of handlePreviousState

void processIncomingByte (const byte c, states & state, unsigned int & currentValue)
{
  if (isdigit (c))
  {
    currentValue *= 10;
    currentValue += c - '0';
  }  // end of digit
  else 
  {

    // The end of the number signals a state change
    handlePreviousState (state, currentValue);

    // set the new state, if we recognize it
    switch (c)
    {
    case 'A':
      state = GOT_A;
      break;
    case 'B':
      state = GOT_B;
      break;
    case 'C':
      state = GOT_C;
      break;
    case 'D':
      state = GOT_D;
      break;
    case 'E':
      state = GOT_E;
      break;
    case 'F':
      state = GOT_F;
      break;
    case 'G':
      state = GOT_G;
      break;
    case 'H':
      state = GOT_H;
      break;
    case 'I':
      state = GOT_I;
      break;
    case 'J':
      state = GOT_J;
      break;
    case 'K':
      state = GOT_K;
      break;
    case 'L':
      state = GOT_L;
      break;
    default:
      state = NONE;
      break;
    }  // end of switch on incoming byte
  } // end of not digit  

} // end of processIncomingByte

PaulS:
Sit on your ass doing nothing, waiting for the buffers to overflow. What a great idea. NOT!

He got the delay down to zero, Paul, so that's good, eh?

int del=0;  //delay value if needed

Final-ish code:

Receiving from both serial ports, no mixed up data, but only issue is that its not read port A, read port B, read port A, etc
its pretty random how it samples the two ports.

I tried it in both wired and wireless configurations and still get un even sampling...

All I did was take Nicks code and duplicate it....

int del=0;  //delay value if needed
typedef enum {  NONE, GOT_A, GOT_B, GOT_C, GOT_D, GOT_E, GOT_F, GOT_AA, GOT_BB, GOT_CC, GOT_DD, GOT_EE, GOT_FF} states;
states stateA = NONE;
states stateB = NONE;
unsigned int currentValueA;
unsigned int currentValueB;

void setup() {
  Serial.begin(115200);  //initialize serial for displaying data to screen
  Serial2.begin(57600); //initialize serial for receiving Sensor unit A data
  Serial3.begin(57600); //initialize serial for receiving Sensor unit B data
}

void loop() 
{
  if (Serial2.available ())
    processIncomingByteA (Serial2.read ());
      if (Serial3.available ())
    processIncomingByteB (Serial3.read ());

  //delay(del); //delay if needed

}


void processA (const unsigned int valueA)
{
  Serial.print ("1A = ");
  Serial.println (valueA);
}

void processB (const unsigned int valueA)
{
   Serial.print ("1B = ");
  Serial.println (valueA);
} 

void processC (const unsigned int valueA)
{
   Serial.print ("1C = ");
  Serial.println (valueA);  
} 

void processD (const unsigned int valueA)
{
  Serial.print ("1D = ");
  Serial.println (valueA);
} 

void processE (const unsigned int valueA)
{
  Serial.print ("1E = ");
  Serial.println (valueA);
} 

void processF (const unsigned int valueA)
{
  Serial.print ("1F = ");
  Serial.println (valueA);
} 

void processAA (const unsigned int valueB)
{
  Serial.print ("2A = ");
  Serial.println (valueB);
}

void processBB (const unsigned int valueB)
{
   Serial.print ("2B = ");
  Serial.println (valueB);
} 

void processCC (const unsigned int valueB)
{
   Serial.print ("2C = ");
  Serial.println (valueB);  
} 

void processDD (const unsigned int valueB)
{
  Serial.print ("2D = ");
  Serial.println (valueB);
} 

void processEE (const unsigned int valueB)
{
  Serial.print ("2E = ");
  Serial.println (valueB);
} 

void processFF (const unsigned int valueB)
{
  Serial.print ("2F = ");
  Serial.println (valueB);
}

void handlePreviousStateA ()
{
  switch (stateA)
  {
  case GOT_A:
    processA (currentValueA);
    break;
  case GOT_B:
    processB (currentValueA);
    break;
  case GOT_C:
    processC (currentValueA);
    break;
      case GOT_D:
    processD (currentValueA);
    break;
      case GOT_E:
    processE (currentValueA);
    break;
      case GOT_F:
    processF (currentValueA);
    break;
     
  }  // end of switch  

  currentValueA = 0; 
}  // end of handlePreviousState


void handlePreviousStateB ()
{
  switch (stateB)
  {
  case GOT_AA:
    processAA (currentValueB);
    break;
  case GOT_BB:
    processBB (currentValueB);
    break;
  case GOT_CC:
    processCC (currentValueB);
    break;
      case GOT_DD:
    processDD (currentValueB);
    break;
      case GOT_EE:
    processEE (currentValueB);
    break;
      case GOT_FF:
    processFF (currentValueB);
    break;
     
  }  // end of switch  

  currentValueB = 0; 
}  // end of handlePreviousState



void processIncomingByteA (const byte c)
{
  if (isdigit (c))
  {
    currentValueA *= 10;
    currentValueA += c - '0';
  }  // end of digit
  else 
  {

    // The end of the number signals a state change
    handlePreviousStateA ();

    // set the new state, if we recognize it
    switch (c)
    {
    case 'A':
      stateA = GOT_A;
      break;
    case 'B':
      stateA = GOT_B;
      break;
    case 'C':
      stateA = GOT_C;
      break;
          case 'D':
      stateA = GOT_D;
      break;
    case 'E':
      stateA = GOT_E;
      break;
    case 'F':
      stateA = GOT_F;
      break;

    default:
      stateA = NONE;
      break;
    }  // end of switch on incoming byte
  } // end of not digit  
  
} // end of processIncomingByte



void processIncomingByteB (const byte c)
{
  if (isdigit (c))
  {
    currentValueB *= 10;
    currentValueB += c - '0';
  }  // end of digit
  else 
  {

    // The end of the number signals a state change
    handlePreviousStateB ();

    // set the new state, if we recognize it
    switch (c)
    {
    case 'A':
      stateB = GOT_AA;
      break;
    case 'B':
      stateB = GOT_BB;
      break;
    case 'C':
      stateB = GOT_CC;
      break;
          case 'D':
      stateB = GOT_DD;
      break;
    case 'E':
      stateB = GOT_EE;
      break;
    case 'F':
      stateB = GOT_FF;
      break;

    default:
      stateB = NONE;
      break;
    }  // end of switch on incoming byte
  } // end of not digit  
  
} // end of processIncomingByte

SAMPLE DATA:

2E = 1024
2F = 0
2A = 1024
1A = 1024
2B = 1024
1B = 1024
2C = 1024
1C = 1024
2D = 1024
1D = 1024
2E = 1024
1E = 1024
2F = 0
1F = 0
1A = 1024
1B = 1024
1C = 1024
1D = 1024
1E = 1024
1F = 0
2A = 1024
2B = 1024
2C = 1024
1A = 1024

I tried it in both wired and wireless configurations and still get un even sampling...

Perhaps you should read all the data from one port, then read all the data from the other port - using while, not if.

Didn't see you replied Nick,
Ill check out your latest sample code.... what I just posted is not taking into account your last post :slight_smile:

Paul, always nice hearing from you :wink:

Ok your code is nice!!!

What I am doing is building a set of VR gloves taking analog sensor data from 10 fingers.
Each hand has its own transmitter.. each receives sensor data calibrates it maps it and sends it out as a serial stream wirelessly to a single receiving unit that reads each transmitter on a separate serial port. I built in an option to go to wired mode in case of interference so I can check my data both ways and they both seem very similar... so interference is not an issue right now.

The reason for all of the prefixes is that each letter represented a finger.
I initially had A,B,C,D,E,F,G,H,I,J,K,&L as my prefixes,
but in the new code I used only A-F on both gloves that way if any piece of hardware ever fails the transmitters can be interchangeable.

In the receiving sketch I still separated the two by calling an 'A' reading from hand #2 'AA' , 'B' reading 'BB', etc
but ultimately it works!!! just don't quite grasp why the data packets are not alternating from right hand to left hand and back evenly....

For those of you with similar issues here is my final code... working good!!!
its based on Nick Gammons excellent tutorial and code examples which he linked earlier in this thread.

TX code:

//limits for sensor range
int digit1UL=330;
int digit1LL=330;
int digit2UL=330;
int digit2LL=330;
int digit3UL=330;
int digit3LL=330;
int digit4UL=330;
int digit4LL=330;
int digit5UL=330;
int digit5LL=330;

int del=10; // delay if needed to keep serial from overflowing
int aux; //aux switch value (on/off)

void setup(){
  Serial.begin(57600);
  pinMode(3, INPUT); //Lower Limit
  pinMode(4, INPUT);// Upper limit
  pinMode(6, INPUT);// Aux switch
}

void loop(){
  // read all sensors
  int buttonA=digitalRead(3);// Upper limit
  int buttonB=digitalRead(4);//Lower limit
  int buttonC=digitalRead(6);//Aux switch
  int thumbSensorReading1 = analogRead(A0);
  int indexSensorReading2 = analogRead(A1);
  int middleSensorReading3 = analogRead(A2);
  int ringSensorReading4 = analogRead(A3);
  int pinkySensorReading5 = analogRead(A4);

  //calibrate unit
  if (buttonA==HIGH && buttonB==LOW){ //Button A pressed = high limit set
    digit1UL=thumbSensorReading1;
    digit2UL=indexSensorReading2;
    digit3UL=middleSensorReading3;
    digit4UL=ringSensorReading4;
    digit5UL=pinkySensorReading5;
  }

  if (buttonB==HIGH && buttonA==LOW){ //Button B pressed = low limit set
    digit1LL=thumbSensorReading1;
    digit2LL=indexSensorReading2;
    digit3LL=middleSensorReading3;
    digit4LL=ringSensorReading4;
    digit5LL=pinkySensorReading5;
  }

  if (buttonC==HIGH ) //Button C pressed = Aux ON
    aux=1024; 
  else aux=0;


  //modify sensor values based on calibration parameters
  int adjustedReading1=map(thumbSensorReading1,digit1LL,digit1UL,1024,0);
  adjustedReading1=constrain(adjustedReading1,0,1024);
  int adjustedReading2=map(indexSensorReading2,digit2LL,digit2UL,1024,0);
  adjustedReading2=constrain(adjustedReading2,0,1024);
  int adjustedReading3=map(middleSensorReading3,digit3LL,digit3UL,1024,0);
  adjustedReading3=constrain(adjustedReading3,0,1024);
  int adjustedReading4=map(ringSensorReading4,digit4LL,digit4UL,1024,0);
  adjustedReading4=constrain(adjustedReading4,0,1024);
  int adjustedReading5=map(pinkySensorReading5,digit5LL,digit5UL,1024,0);
  adjustedReading5=constrain(adjustedReading5,0,1024);


  //OUTPUT DATA TO SERIAL PORT
  Serial.print('A'); //Header character to let receiver know what sensor the value received is associated with
  Serial.print(adjustedReading1); // send actual sensor value
  
  Serial.print('B');
  Serial.println(adjustedReading2);
  
  Serial.print('C');
  Serial.println(adjustedReading3);
  
  Serial.print('D');
  Serial.println(adjustedReading4);
  
  Serial.print('E');
  Serial.println(adjustedReading5);
  
  Serial.print('F'); // this is the auxillary switch (on or off)
  Serial.println(aux);
  delay(del);
}

RX code:

int del=0;  //delay value if needed
typedef enum {  NONE, GOT_A, GOT_B, GOT_C, GOT_D, GOT_E, GOT_F, GOT_AA, GOT_BB, GOT_CC, GOT_DD, GOT_EE, GOT_FF} states;
states stateA = NONE;
states stateB = NONE;
unsigned int currentValueA;
unsigned int currentValueB;

void setup() {
  Serial.begin(115200);  //initialize serial for displaying data to screen
  Serial2.begin(57600); //initialize serial for receiving Sensor unit A data
  Serial3.begin(57600); //initialize serial for receiving Sensor unit B data
}

void loop() 
{
  if (Serial2.available ())
    processIncomingByteA (Serial2.read ());
      if (Serial3.available ())
    processIncomingByteB (Serial3.read ());

  //delay(del); //delay if needed

}


void processA (const unsigned int valueA)
{
  Serial.print ("    1A = ");
  Serial.print (valueA);
}

void processB (const unsigned int valueA)
{
   Serial.print ("    1B = ");
  Serial.print (valueA);
} 

void processC (const unsigned int valueA)
{
   Serial.print ("    1C = ");
  Serial.print (valueA);  
} 

void processD (const unsigned int valueA)
{
  Serial.print ("    1D = ");
  Serial.print (valueA);
} 

void processE (const unsigned int valueA)
{
  Serial.print ("    1E = ");
  Serial.print (valueA);
} 

void processF (const unsigned int valueA)
{
  Serial.print ("    1F = ");
  Serial.print (valueA);
} 

void processAA (const unsigned int valueB)
{
  Serial.print ("    2A = ");
  Serial.print (valueB);
}

void processBB (const unsigned int valueB)
{
   Serial.print ("    2B = ");
  Serial.print (valueB);
} 

void processCC (const unsigned int valueB)
{
   Serial.print ("    2C = ");
  Serial.print (valueB);  
} 

void processDD (const unsigned int valueB)
{
  Serial.print ("    2D = ");
  Serial.print (valueB);
} 

void processEE (const unsigned int valueB)
{
  Serial.print ("    2E = ");
  Serial.print (valueB);
} 

void processFF (const unsigned int valueB)
{
  Serial.print ("    2F = ");
  Serial.print (valueB);
}

void handlePreviousStateA ()
{
  switch (stateA)
  {
  case GOT_A:
    processA (currentValueA);
    break;
  case GOT_B:
    processB (currentValueA);
    break;
  case GOT_C:
    processC (currentValueA);
    break;
      case GOT_D:
    processD (currentValueA);
    break;
      case GOT_E:
    processE (currentValueA);
    break;
      case GOT_F:
    processF (currentValueA);
    break;
     
  }  // end of switch  

  currentValueA = 0; 
}  // end of handlePreviousState


void handlePreviousStateB ()
{
  switch (stateB)
  {
  case GOT_AA:
    processAA (currentValueB);
    break;
  case GOT_BB:
    processBB (currentValueB);
    break;
  case GOT_CC:
    processCC (currentValueB);
    break;
      case GOT_DD:
    processDD (currentValueB);
    break;
      case GOT_EE:
    processEE (currentValueB);
    break;
      case GOT_FF:
    processFF (currentValueB);
    break;
     
  }  // end of switch  

  currentValueB = 0; 
}  // end of handlePreviousState



void processIncomingByteA (const byte c)
{
  if (isdigit (c))
  {
    currentValueA *= 10;
    currentValueA += c - '0';
  }  // end of digit
  else 
  {

    // The end of the number signals a state change
    handlePreviousStateA ();

    // set the new state, if we recognize it
    switch (c)
    {
    case 'A':
      stateA = GOT_A;
      break;
    case 'B':
      stateA = GOT_B;
      break;
    case 'C':
      stateA = GOT_C;
      break;
          case 'D':
      stateA = GOT_D;
      break;
    case 'E':
      stateA = GOT_E;
      break;
    case 'F':
      stateA = GOT_F;
      break;

    default:
      stateA = NONE;
      break;
    }  // end of switch on incoming byte
  } // end of not digit  
  
} // end of processIncomingByte



void processIncomingByteB (const byte c)
{
  if (isdigit (c))
  {
    currentValueB *= 10;
    currentValueB += c - '0';
  }  // end of digit
  else 
  {

    // The end of the number signals a state change
    handlePreviousStateB ();

    // set the new state, if we recognize it
    switch (c)
    {
    case 'A':
      stateB = GOT_AA;
      break;
    case 'B':
      stateB = GOT_BB;
      break;
    case 'C':
      stateB = GOT_CC;
      break;
          case 'D':
      stateB = GOT_DD;
      break;
    case 'E':
      stateB = GOT_EE;
      break;
    case 'F':
      stateB = GOT_FF;
      break;

    default:
      stateB = NONE;
      break;
    }  // end of switch on incoming byte
  } // end of not digit  
  
} // end of processIncomingByte

The Tx code is loaded into each of the two arduinos serving as part of the transmitters.
It spits out a letter (A-F) which represents a label for each of 5 sensors and a switch (F)
followed by the value of each sensor (for switch F it either spits out a 0 or a 1024 for ON/OFF)

The RX end reads Serial port 2 and 3 and processes the incoming data and prints it to Serial0 at double the baud rate.
It prints something like (1F= 1024 or 2A=247)
the first 1 or 2 tells us what port the data was received from. The letter is the specific sensor label and then the last numbers are the values for that sensor on that port.

You should be able to easily modify the code to suit your needs!!!!

int del=10; // delay if needed to keep serial from overflowing

The delay is in every pass through loop. It has nothing to do with serial data. The outgoing serial buffer can not overflow, since Serial.print() and Serial.write() block if there is no room in the buffer. Please fix the comment.

As you’ve learned, it is not necessary to delay when reading serial data coming in. In fact, doing do is bad. So, everything involving del in the receiver code needs to hit the bit bucket, too.

Thanks PaulS will correct it

Here is an updated sketch set (RX/TX sketches)
I changed minor things like adding debug sections to both sketches and made it so it autocalibrates at startup (SETUP())

I tried a few tests without the delay but my data was completely wrong.

The delay in the Tx side was the only thing that corrected it. With no delay it looked like the Rx end was not catching all of the line endings and id get data that should read:

A=1234
looking like
A=1234
A=123412...
A=1234123....
A=1234....
etc

The Tx delay started at 10 and by the time it was up to 20 the data was perfectly clean.

PaulS maybe you can chime in here... I know you understand this better than me so there must be ore to it... Im just going by trial and error...

TX CODE:

//VR GLOVE TX SKETCH


//limits for sensor range
int digit1UL;
int digit1LL;
int digit2UL;
int digit2LL;
int digit3UL;
int digit3LL;
int digit4UL;
int digit4LL;
int digit5UL;
int digit5LL;
int buttonA;
int buttonB;
int buttonC;
int thumbSensorReading1;
int indexSensorReading2;
int middleSensorReading3;
int ringSensorReading4;
int pinkySensorReading5;
int del=20; // delay if needed to keep serial from overflowing
int aux; //aux switch value (on/off)

void setup(){
  Serial.begin(57600);
  pinMode(3, INPUT); //Lower Limit
  pinMode(4, INPUT);// Upper limit
  pinMode(6, INPUT);// Aux switch

  buttonC=digitalRead(6);//Aux switch
  digit1UL = analogRead(A0)+50;
  digit1LL = digit1UL-100;
  digit2UL = analogRead(A0)+50;
  digit2LL = digit2UL-100;
  digit3UL = analogRead(A0)+50;
  digit3LL = digit3UL-100;
  digit4UL = analogRead(A0)+50;
  digit4LL = digit4UL-100;
  digit5UL = analogRead(A0)+50;
  digit5LL = digit5UL-100;
}

void loop(){
  // read all sensors
  buttonA=digitalRead(3);// Upper limit
  buttonB=digitalRead(4);//Lower limit
  buttonC=digitalRead(6);//Aux switch
  thumbSensorReading1 = analogRead(A0);
  indexSensorReading2 = analogRead(A1);
  middleSensorReading3 = analogRead(A2);
  ringSensorReading4 = analogRead(A3);
  pinkySensorReading5 = analogRead(A4);

  //calibrate unit
  if (buttonA==HIGH && buttonB==LOW){ //Button A pressed = high limit set
    digit1UL=thumbSensorReading1;
    digit2UL=indexSensorReading2;
    digit3UL=middleSensorReading3;
    digit4UL=ringSensorReading4;
    digit5UL=pinkySensorReading5;
    //Serial.println("BUTTON A IS HIGH");
  }

  if (buttonB==HIGH && buttonA==LOW){ //Button B pressed = low limit set
    digit1LL=thumbSensorReading1;
    digit2LL=indexSensorReading2;
    digit3LL=middleSensorReading3;
    digit4LL=ringSensorReading4;
    digit5LL=pinkySensorReading5;
    //Serial.println("BUTTON B IS HIGH");
  }

  if (buttonC==HIGH ) //Button C pressed = Aux ON
    aux=1024; 
  else aux=0;


  //modify sensor values based on calibration parameters
  int adjustedReading1=map(thumbSensorReading1,digit1LL,digit1UL,1024,0);
  adjustedReading1=constrain(adjustedReading1,0,1024);
  int adjustedReading2=map(indexSensorReading2,digit2LL,digit2UL,1024,0);
  adjustedReading2=constrain(adjustedReading2,0,1024);
  int adjustedReading3=map(middleSensorReading3,digit3LL,digit3UL,1024,0);
  adjustedReading3=constrain(adjustedReading3,0,1024);
  int adjustedReading4=map(ringSensorReading4,digit4LL,digit4UL,1024,0);
  adjustedReading4=constrain(adjustedReading4,0,1024);
  int adjustedReading5=map(pinkySensorReading5,digit5LL,digit5UL,1024,0);
  adjustedReading5=constrain(adjustedReading5,0,1024);


  //OUTPUT DATA TO SERIAL PORT
  Serial.print('A'); //Header character to let receiver know what sensor the value received is associated with
  Serial.print(adjustedReading1); // send actual sensor value

  Serial.print('B');
  Serial.print(adjustedReading2);

  Serial.print('C');
  Serial.print(adjustedReading3);

  Serial.print('D');
  Serial.print(adjustedReading4);

  Serial.print('E');
  Serial.print(adjustedReading5);

  Serial.print('F'); // this is the auxillary switch (on or off)
  Serial.println(aux);
  delay(del);


  //DEBUG
  /*
   Serial.print("thumbSensorReading1=");
   Serial.print(thumbSensorReading1);
   Serial.print("   indexSensorReading2=");
   Serial.print(indexSensorReading2);
   Serial.print("   middleSensorReading3=");
   Serial.print(middleSensorReading3);
   Serial.print("   ringSensorReading4=");
   Serial.print(ringSensorReading4);
   Serial.print("   pinkySensorReading5=");
   Serial.println(pinkySensorReading5);
   Serial.print("   digit1UL="); 
   Serial.print(digit1UL);
   Serial.print("   digit1LL="); 
   Serial.print(digit1LL);
   Serial.print("   digit2UL="); 
   Serial.print(digit2UL);
   Serial.print("   digit2LL="); 
   Serial.print(digit2LL);
   Serial.print("   digit3UL"); 
   Serial.print(digit3UL);
   Serial.print("   digit3LL"); 
   Serial.print(digit3LL);
   Serial.print("   digit4UL="); 
   Serial.print(digit4UL);
   Serial.print("   digit4LL="); 
   Serial.print(digit4LL);
   Serial.print("   digit5UL="); 
   Serial.print(digit5UL);
   Serial.print("   digit5LL="); 
   Serial.println(digit5LL);
   Serial.print("   adjustedReading1="); //Header character to let receiver know what sensor the value received is associated with
   Serial.print(adjustedReading1); // send actual sensor value
   Serial.print("   adjustedReading2=");
   Serial.print(adjustedReading2);
   Serial.print("   adjustedReading3=");
   Serial.print(adjustedReading3);
   Serial.print("   adjustedReading4=");
   Serial.print(adjustedReading4);
   Serial.print("   adjustedReading5=");
   Serial.print(adjustedReading5);
   Serial.print("   adjustedReading5="); // this is the auxillary switch (on or off)
   Serial.print(aux);
   Serial.println();
   */
}

RX CODE:

// VR GLOVE RX SKETCH
// Based on Nick Gammons code www.gammon.com.au/forum/?id=11425

typedef enum {  
  NONE, GOT_A, GOT_B, GOT_C, GOT_D, GOT_E, GOT_F, GOT_AA, GOT_BB, GOT_CC, GOT_DD, GOT_EE, GOT_FF} 
states;
states stateA = NONE;
states stateB = NONE;
unsigned int currentValueA;
unsigned int currentValueB;
int currentA;
int currentB;
int currentC;
int currentD;
int currentE;
int currentF;
int currentAA;
int currentBB;
int currentCC;
int currentDD;
int currentEE;
int currentFF;

void setup() {
  Serial.begin(57600);  //initialize serial for displaying data to screen
  Serial2.begin(57600); //initialize serial for receiving Sensor unit A data
  Serial3.begin(57600); //initialize serial for receiving Sensor unit B data
}

void loop() 
{
  if (Serial2.available ())
    processIncomingByteA (Serial2.read ());
  if (Serial3.available ())
    processIncomingByteB (Serial3.read ());

  //DEBUG
  Serial.print("  currentA=");
  Serial.print(currentA);
  /*
Serial.print("  currentB=");Serial.print(currentB);
   Serial.print("  currentC=");Serial.print(currentC);
   Serial.print("  currentD=");Serial.print(currentD);
   Serial.print("  currentE=");Serial.print(currentE);
   Serial.print("  currentF=");Serial.print(currentF);
   Serial.print("  currentAA=");Serial.print(currentAA);
   Serial.print("  currentBB=");Serial.print(currentBB);
   Serial.print("  currentCC=");Serial.print(currentCC);
   Serial.print("  currentDD=");Serial.print(currentDD);
   Serial.print("  currentEE=");Serial.print(currentEE);
   Serial.print("  currentFF=");Serial.print(currentFF);
   */
  Serial.println(); 
  //delay(10);
}


void processA (const unsigned int valueA)
{ 
  currentA=valueA;
}

void processB (const unsigned int valueA)
{
  currentB=valueA;
} 

void processC (const unsigned int valueA)
{
  currentC=valueA;
} 

void processD (const unsigned int valueA)
{
  currentD=valueA;
} 

void processE (const unsigned int valueA)
{
  currentE=valueA;
} 

void processF (const unsigned int valueA)
{
  currentF=valueA;
} 

void processAA (const unsigned int valueB)
{
  currentAA=valueB;
}

void processBB (const unsigned int valueB)
{
  currentBB=valueB;
} 

void processCC (const unsigned int valueB)
{
  currentCC=valueB;
} 

void processDD (const unsigned int valueB)
{
  currentDD=valueB;
} 

void processEE (const unsigned int valueB)
{
  currentEE=valueB;
} 

void processFF (const unsigned int valueB)
{
  currentFF=valueB;
}

void handlePreviousStateA ()
{
  switch (stateA)
  {
  case GOT_A:
    processA (currentValueA);
    break;
  case GOT_B:
    processB (currentValueA);
    break;
  case GOT_C:
    processC (currentValueA);
    break;
  case GOT_D:
    processD (currentValueA);
    break;
  case GOT_E:
    processE (currentValueA);
    break;
  case GOT_F:
    processF (currentValueA);
    break;

  }  // end of switch  

  currentValueA = 0; 
}  // end of handlePreviousState


void handlePreviousStateB ()
{
  switch (stateB)
  {
  case GOT_AA:
    processAA (currentValueB);
    break;
  case GOT_BB:
    processBB (currentValueB);
    break;
  case GOT_CC:
    processCC (currentValueB);
    break;
  case GOT_DD:
    processDD (currentValueB);
    break;
  case GOT_EE:
    processEE (currentValueB);
    break;
  case GOT_FF:
    processFF (currentValueB);
    break;

  }  // end of switch  

  currentValueB = 0; 
}  // end of handlePreviousState



void processIncomingByteA (const byte c)
{
  if (isdigit (c))
  {
    currentValueA *= 10;
    currentValueA += c - '0';
  }  // end of digit
  else 
  {

    // The end of the number signals a state change
    handlePreviousStateA ();

    // set the new state, if we recognize it
    switch (c)
    {
    case 'A':
      stateA = GOT_A;
      break;
    case 'B':
      stateA = GOT_B;
      break;
    case 'C':
      stateA = GOT_C;
      break;
    case 'D':
      stateA = GOT_D;
      break;
    case 'E':
      stateA = GOT_E;
      break;
    case 'F':
      stateA = GOT_F;
      break;

    default:
      stateA = NONE;
      break;
    }  // end of switch on incoming byte
  } // end of not digit  

} // end of processIncomingByte



void processIncomingByteB (const byte c)
{
  if (isdigit (c))
  {
    currentValueB *= 10;
    currentValueB += c - '0';
  }  // end of digit
  else 
  {

    // The end of the number signals a state change
    handlePreviousStateB ();

    // set the new state, if we recognize it
    switch (c)
    {
    case 'A':
      stateB = GOT_AA;
      break;
    case 'B':
      stateB = GOT_BB;
      break;
    case 'C':
      stateB = GOT_CC;
      break;
    case 'D':
      stateB = GOT_DD;
      break;
    case 'E':
      stateB = GOT_EE;
      break;
    case 'F':
      stateB = GOT_FF;
      break;

    default:
      stateB = NONE;
      break;
    }  // end of switch on incoming byte
  } // end of not digit  

} // end of processIncomingByte

I don't see anything on the receiver side that prints A= anything. Posting some REAL output would be good.

If the delay() on the sender end is needed, use it,

Ill post data tomorrow when Im back at work.
One thing that throws me off with serial communication is that even when I have the code working well and displaying good data on the screen (data in through Serial 2 and 3 and data out to Serial monitor via Serial0)
when I’m done troubleshooting and comment out the Serial 0 port lines… suddenly the data is not the same…
But I cant see why… just know because it makes the device stop responding to the data coming in.

Is there a better way to troubleshoot serial data so as to not affect the functionality of the code???

Correctly written code should be reasonably resistant to debugging prints (if you don't overdo them, and thus block the processor).

Here are some other tips for debugging: