# Efficient reading and parsing of continous serial data

**URL:** <https://community.particle.io/t/efficient-reading-and-parsing-of-continous-serial-data/33655>\
**Category:** General\
**Created:** [June 10, 2017, 10:05am UTC](https://community.particle.io/t/efficient-reading-and-parsing-of-continous-serial-data/33655 "2017-06-10T10:05:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jimmie](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@Jimmie](https://community.particle.io/u/Jimmie)\
**Post date:** [June 10, 2017, 10:05am UTC](https://community.particle.io/t/efficient-reading-and-parsing-of-continous-serial-data/33655/1 "2017-06-10T10:05:01Z")

</div>

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 …

```auto

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;
}

```

---

<div class="post-metadata">

**Author:** ![Jimmie](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@Jimmie](https://community.particle.io/u/Jimmie)\
**Post date:** [June 12, 2017, 10:25pm UTC](https://community.particle.io/t/efficient-reading-and-parsing-of-continous-serial-data/33655/2 "2017-06-12T22:25:56Z")

</div>

Solved it using this excellent link and tutorial:

[https://forum.arduino.cc/index.php?topic=396450.0](https://forum.arduino.cc/index.php?topic=396450.0)
