I am trying to send multiple servo angles via a serial connection from Processing to Arduino. However, when I run both programs, the connection seems to be flakey -- sometimes it works, and other times it doesn't. I have included some of my code below this message. I would really appreciate any help.
Are servoID, servo1Angle, and servo2Angle bytes in the Processing program?
Are base, baseID , shoulder, and shoulderID all bytes in the Arduino program?
Are you aware that serial data delivery follows the USPS business, where delivery is not guaranteed? The only guarantee is that an attempt will be made to deliver the data.
If any one of the 4 bytes sent does not make it, all subsequent data will be wrong, until 3 more bytes get lost.
I always recommend start and end markers for packets:
.
Read serial data until you see a start marker (<). Then, read until and store the data in an array until you see an end marker (>). If there are 4 bytes in the array, the data is probably good. If there are fewer than 4 or more than 4, toss that incomplete/corrupt packet.
The variables should all be byte, since that is the type of data being sent.