0
votes

I am using Processing to send an array of bytes to an Arduino card via a serial port. I have a strange problem where the Arduino doesn't seem to read the array "in sync" - the byte elements appear shifted to the Arduino code.

For example, from Processing I send array:

array = [0, 1, 2, 3, 4];

and the Arduino could read it as:

array = [2, 3, 4, 0, 1];

This problem appears at random - about 1/3 times I try, and the shift is always random as well. When it works it continues to work for the duration of the session, until i restart the connection.

Have anyone else encountered similar problems? Do you have any suggestions as of how to fix this problem?

Regards, Tobias

1

1 Answers

1
votes

Could you provide a code sample showing how you send and read bytes? Especially reading by arduino code is important.

It's not clear how you synchronize the transmission: assuming you send 5 bytes - how does the Arduino code detect when it receives a complete array? If you rely on a serial port buffer and just count to 5 incoming bytes assuming they make up an array examine what happens if at least once there was a byte missing (e.g. due to Processing code restart while some bytes were already sent to the Arduino).