- Home /
delay sending to serial port
Hi
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){ sp.Write(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)
Answer by Famulus · Aug 23, 2012 at 09:11 AM
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.
Your answer
Follow this Question
Related Questions
Uniduino, Arduino & Unity 5 3 Answers
Serial Port delay is getting longer 0 Answers
Send data through usb using android phone 0 Answers
Arduino with Unity: Bad Framerate! 3 Answers