Checking Boolean variable breaks serial communication code with Arduino

Hi @grudovz. It’s very easy to make a serial comms arrangement that appears to be correct but locks up if something varies. The ‘something’ might be that the Arduino is not ready (because it resets when Processing connects) or Processing hangs for a moment while the O.S. is busy. Where you test for ‘available’ you are not waiting to ensure all the characters have arrived (yes, think you are only using 2). You are transmitting an id and a value, but nothing to identify which is which. With that scheme I’ve always wondered if it can be relied on that everything stays in step. I think you are using binary data, which is alright, but ascii (text) is much easier to work with because you can print it directly.

Some months ago I made an example which tolerates all the known (by me) issues and just works. You might like to try it.

You can always add print statements to the Processing code to see what it’s doing. The Arduino can be more difficult. Please say what Arduino you have, and whether you have anything on it to help see what it’s doing (other serial connections, leds, led screens…).

1 Like