while(cam.available()>0)
{
//int temp = cam.read();
//Serial.print(temp); Serial.print("/t");
if (cam.read() == 0x0A)
{
//Serial.println(temp,HEX);
//byte initial = byte(cam.read());
numTrack = byte(cam.read());
FillData();
}
}
The while loop will be entered if there is one byte ready to be read. You then read two bytes. Not a good thing.
Then, you call FillData to read the remaining 40 bytes of the one that has arrived. Again, not a good thing.
My thought is to use Serial.read() and Serial.peek() to read 0xFF(dec255) and then if Serial.peek() = 0x0A essentially if(Serial.read()==0xFF && Serial.peek() == 0x0A) the next data you would store is the number of tracked objects.
You don't need to be peeking. You do need to be waiting for the serial data to arrive.
I consistently read values like 88 hex etc which are or 100+ decimal values. I understand reading the data in, its syncing the bytes properly.
I disagree. You don't understand serial data transmission at all. Hopefully, now you see the problem, and a way to address the issue.
I've seen mention of reading the data into a string and separating it out but, there arent any data separators so I think I need to do it byte by byte.
Especially as it is not character data being received.