Hello,
I have a sensor which is outputting data at a high rate (200 Hz). The data always starts with a value of 222 followed by the information and then it repeats.
I would appreciate example code showing how to correctly and efficiently parse this data then display EACH value before reading the next value …? I am using the code below but it is not efficient as I am throwing away the remainder of the buffer as you can see below …
float takeReading()
{
digitalWrite(rs485Pin, LOW); // Disable RS485 Transmit
len = Serial1.readBytes((char *)buf, 8); //Process after 8 Bytes
if (len > 0)
{
for (int i = 0; i <= len - 2; i++)
{
if (buf[i] == 222)
{
measure = (int(buf[i + 1]) + (buf[i + 2]));
i = i + 2;
break; //Leave for
}
}
}
Serial1.flush();
return measure;
}