Ok so I tried a > 5 and the results worked. Though I'm not sure I get the logic behind it and will break that down for further study. In effort to move on with the test, the results are unexpected but do show. I expected the following to happen:
reading Serial String:
00000
but get the following results which was unexpected:
reading Serial String:
.....
reading Serial String:
.....
reading Serial String:
00000
I had to add Serial1.flush(); to end of loop otherwise it would continuously loop with same serial data. I thought once you read the serial buffer it is cleared. So the flush seemed to handle that. Though I can not explain the tripple posting each time new serial data is detected. I have attached the code with current revisions.
uint8_t LcdRcvPacket[] = { 0, 0, 0, 0, 0}; // payload from Serial1
// Payload sent over serial port like this 00000 (broken out would be 0,000,0,0,0)see below for posisbel data ranges
int Data1, Data2, Data3, Data4, Data5;
void setup()
{
// Open serial communications and wait for port to open:
Serial1.begin(9600); // Mega 2560
Serial.begin(9600); // Serial Com port on PC
}
void loop() // Repeat over and over
{
if(Serial1.available()) // If serial Data detected then process otherwise bypass
{ // If LCD data avaiable get it
Serial.println("reading Serial String: "); //Debug code
while (Serial1.available() > 5)
{
for(int n=0; n < 5; n++)
LcdRcvPacket[n] = Serial1.read(); // Assign LCD data into a array for processing
delay(500);
}
// Parse Array into indavidual variables
Data1 = LcdRcvPacket[0];
Data2 = LcdRcvPacket[1];
Data3 = LcdRcvPacket[2];
Data4 = LcdRcvPacket[3];
Data5 = LcdRcvPacket[4];
Serial.write(Data1); //Data range 0-1
Serial.write(Data2); //Data range 0-100
Serial.write(Data3); //Data range 1-3
Serial.write(Data4); //Data range 1-3
Serial.write(Data5); //Data range 0-1
Serial.println();
}
Serial1.flush();
// If no serial data then do somthing else, or process data detected that was captured.
}