Syncing Arduino sensor value reads with Unity

Dear Community,

I wanna read 9 different sensor values from an Arduino in Unity. The values are stored in one single line per reading with delay(100) e.g. “# -0.01 # -0.02 # 0.88 # 31.49 # -1.18 # 0.11 # -2.21 # 0 # 0”. However when I want to read out all values in unity not all values are transferred. How can I sync the reading so that all values are updated correctly?

public class SphereManipulator : MonoBehaviour
{
    public GameObject panel;

    SerialPort sp = new SerialPort("/dev/cu.usbmodem14201", 9600); // opens a new serial port to the Arduino
    private string[] rawValues; // represents the values from the Arduino

    // Start is called before the first frame update
    void Start()
    {
        sp.Open();
        sp.ReadTimeout = 1; // necessary so that unity can find the port
        rawValues = new string[9];

        parseData();
    }

    // Update is called once per frame
    void Update()
    {
        if (sp.IsOpen)
        {
            try
            {
                bool check = parseData();
               
                if (check)
                    print(rawValues[0] + " " + rawValues[1] + " " + rawValues[2] + " " + rawValues[3] + " " + rawValues[4]);
                 
            }
            catch (System.Exception)
            {
            }
        }
    }

    private bool parseData()
    {
        string data = sp.ReadLine();
        rawValues = data.Split('#');

        // Checks if data input is complete
        foreach (var sensorValue in rawValues)
        {
            if (sensorValue == "")
                return false;
        }
       
        return true;
    }
}

4704698--444263--Screen Shot 2019-07-02 at 9.35.02 AM.png

what kind of string you get in that single sp.ReadLine (if you print it out) ?

 if (check)
                    print(rawValues[0] + " " + rawValues[1] + " " + rawValues[2] + " " + rawValues[3] + " " + rawValues[4]);

you’re printing only then first 5 values.

Also make a timer to read your serial device every 100 ms and to have no FPS drop from time to time, use a couroutine to read the device.