delay sending to serial port


I’ve managed to get a script to send a stream of single digits from a scene to an Arduino board, so that a different LED lights up for each digit. However, there is a significant delay after the first light, and most of the sequence of lights happens after I close the scene. (Working in Play mode, with the signals being sent from a function called in Update).

Can anyone suggest why there should be such a delay please? If I send a fixed string of digits (eg 01234567) from the Start function, it works fine, it’s only in the Update function that the delay happens.

The following function is called from Update() with the digit to be sent to Arduino as ‘number’. sp is a public Serial Port object that has been opened and seems to work OK; the sp.Write is the command I’m concerned with. (The rest of the function sends information to GUIText just so I can see what’s going on).

public void sendToArduino(string number){
	message = "Direction " + number + ", Time " + Time.time;
	orientation.SendMessage("ShowMessage", message);

PS: I’ve flagged this as code, but it’s lost the layout - is that how it should appear? :0)

OK - I think I’ve cracked it, by using a timer to send to Arduino at fixed intervals. I knew I’d need to do that for other reasons, but didn’t realise that it would help with this problem.

So I’ve set a timer to count up, and only send to Arduino when it reaches 1 second, then reset the timer to 0. All I need to do now is play around with it, to work out how small an interval is viable for what I need to do.